using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.UI; /******************************************************************************** *Create By CG *Function 点击Tap切换文本输入框 *********************************************************************************/ namespace CG.UTility { public class InputFieldController : MonoBehaviour, ISelectHandler, IDeselectHandler { private bool isSelect = false; private EventSystem system; // Use this for initialization void Start() { system = EventSystem.current; } private void GetTabDown() { if (Input.GetKeyDown(KeyCode.Tab) && isSelect) { //下一个要切换到的 Selectable next = null; //现在正处在能够处理事件的 Selectable now = system.currentSelectedGameObject.GetComponent(); //找到现在的下一个 next = now.FindSelectableOnDown(); if (next == null) { print("没有下一个了"); } //让下一个能够处理事件 system.SetSelectedGameObject(next.gameObject); } } // Update is called once per frame void Update() { GetTabDown(); } /// /// 实现ISelectHandler接口 /// /// public void OnSelect(BaseEventData eventData) { isSelect = true; } /// /// 实现IDeselectHandler接口 /// /// public void OnDeselect(BaseEventData eventData) { isSelect = false; } } }