2018-04-27 UGUI InputField获取输入焦点

UGUI中的InputField控件如何自动获取输入焦点:

方法1:InputField.ActivateInputField

usingUnityEngine;

usingSystem.Collections;usingUnityEngine.UI;

publicclassExample : MonoBehaviour 

{

publicInputField mainInputField;

// Activate the main input field when the scene starts.

void Start ()    {        mainInputField.ActivateInputField();  

  }}


方法2 EventSystem.SetSelectedGameObject

usingUnityEngine;

usingSystem.Collections;

usingUnityEngine.UI;

publicclassExample : MonoBehaviour

 {

public  InputField   mainInputField;// Activate the main input field when the scene starts.

void    Start ()    {        EventSystem.current.SetSelectedGameObject(mainInputField.gameObject);    }}

你可能感兴趣的:(2018-04-27 UGUI InputField获取输入焦点)