UGUI中按Tab切换InputField
来源:互联网 发布:mac适合做java开发吗 编辑:程序博客网 时间:2024/05/29 19:05
目前的UGUI在InputField里即使设置了Navigation也是不可以用键盘切换上下,所以自己写了个组件实现这个功能
前提条件是要在InputField里设置Navigation,也就是必须能找到上一个控件和下一个控件然后将以下脚本挂在需要切换的InputField上,用Tab和Shift+Tab切换:
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(); if (next == null) next = system.lastSelectedGameObject.GetComponent<Selectable>(); } else { next = system.currentSelectedGameObject.GetComponent<Selectable>().FindSelectableOnDown(); if (next == null) next = system.firstSelectedGameObject.GetComponent<Selectable>(); } 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; }}
阅读全文
0 0
- UGUI中按Tab切换InputField
- UGUI中按Tab切换InputField
- UGUI中按Tab切换InputField
- UGUI中按Tab切换InputField
- UGUI中按Tab切换InputField
- UGUI 中Tab切换 InputField
- UGUI Tab键切换InputField
- Unity 5.4可用的UGUI中按Tab切换InputField脚本
- Unity3D 使用“Shift+Tab”和“Tab”键 上下切换 UGUI下 Dropdown和inputfield等控件的控制顺序
- 关于UGUI中Button,InputField等不响应的解决方法
- UGUI InputField获取输入焦点
- Unity UGUI基础之InputField
- UGUI InputField获取输入焦点
- UGUI 学习笔记10 InputField
- UGUI内核大探究(十六)InputField
- Unity ulua ugui 获取 InputField 框
- $().tab() bootStrap中Tab页签切换
- Tab键对InputField进行换行处理
- <iOS常见问题>之苹果证书无法导出p12格式的文件
- 算法之汉诺塔
- windows批处理脚本 --- 笔记
- 安卓手机的指纹按钮做成苹果的home键
- 升级到ionic3 Lazy Loading懒加载,ionic3新建页面
- UGUI中按Tab切换InputField
- TCP心跳 | TCP keepAlive(转)
- 51Nod 1088 最长回文串
- 嵌入式Qt开发环境的搭建
- 听说,在巴别鸟评审文件特别快?
- linux学习---lamp环境搭建
- Java浮点运算中特殊的情况NAN与Infinity
- Lessons learned while converting to Kotlin with Android Studio
- ibatis调用存储过程的实现