首页 > 编程语言 > 详细

unity 按tab键切换下一个inputfild

时间:2018-01-17 21:44:02      阅读:771      评论:0      收藏:0      [点我收藏+]
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;  
    }  
} 

 

unity 按tab键切换下一个inputfild

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!