unity 按tab键切换下一个inputfild

时间:2018-01-17 21:44:02   收藏:0   阅读:771
using UnityEngine;  
using UnityEngine.UI;  
using UnityEngine.EventSystems;  
  
public class InputNavigator : MonoBehaviour, ISelectHandler, IDeselectHandler  
{  
    EventSystem _system;  
    private bool _isSelect = false;  
  
    void Start()  
    {  
        _system = EventSystem.current;  
    }  
  
    void Update()  
    {  
        if (Input.GetKeyDown(KeyCode.Tab) && _isSelect)  
        {  
  
            Selectable next = null;  
            if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift))  
            {  
                next = _system.currentSelectedGameObject.GetComponent<Selectable>().FindSelectableOnUp();  
            }  
            else  
            {  
                next = _system.currentSelectedGameObject.GetComponent<Selectable>().FindSelectableOnDown();  
            }  
            if (next != null)  
            {  
                InputField inputfield = next.GetComponent<InputField>();  
                _system.SetSelectedGameObject(next.gameObject, new BaseEventData(_system));  
            }  
            else  
            {  
                Debug.LogError("找不到下一个控件");  
            }  
        }  
    }  
  
    public void OnSelect(BaseEventData eventData)  
    {  
        _isSelect = true;  
    }  
  
    public void OnDeselect(BaseEventData eventData)  
    {  
        _isSelect = false;  
    }  
} 

 

原文:https://www.cnblogs.com/0315cz/p/8306052.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!