UGUI InputField获取输入焦点

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

方法1:InputField.ActivateInputField

using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class Example : MonoBehaviour {

    public InputField mainInputField;

    // Activate the main input field when the scene starts.
    void Start () 
    {
        mainInputField.ActivateInputField();
    }
}

方法2 EventSystem.SetSelectedGameObject

using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class Example : MonoBehaviour {

    public InputField mainInputField;

    // Activate the main input field when the scene starts.
    void Start () 
    {
         EventSystem.current.SetSelectedGameObject(mainInputField.gameObject);
    }
}

你可能感兴趣的:(U3D,UGUI)