using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
public class InputFieldSelectExample : MonoBehaviour
{
public InputField inputField; // 在Inspector中设置或者通过代码获取
void Start()
{
EventTrigger trigger = inputField.gameObject.AddComponent<EventTrigger>();
var entry = new EventTrigger.Entry();
entry.eventID = EventTriggerType.Select;
entry.callback.AddListener((data) => { OnInputFieldSelect((BaseEventData)data); });
trigger.triggers.Add(entry);
}
private void OnInputFieldSelect(BaseEventData baseEventData)
{
// 处理输入框被选中的逻辑
Debug.Log("InputField was selected.");
}
}
01-03
2208
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
07-22
1990
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
08-21
1627
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)