UGUI中按Tab切换InputField
来源:互联网 发布:js replacefirst 编辑:程序博客网 时间:2024/06/06 02:05
本文转自风冻冰痕博客,固定链接: http://icemark.cn/blog/?p=253
目前的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进行换行处理
- centos 7 U盘安装教程
- Azure 中部署Gitlab的方法
- 升级openssh【HP-UX】
- GPIO控制led亮暗
- js获取浏览器高度和宽度值
- UGUI中按Tab切换InputField
- 浏览器兼容-----前端最头疼的问题
- 【deeplearning.ai笔记第二课】2.2 优化算法(动量梯度下降,RMSprop,adam)
- 二段提交协议、三段提交协议
- 深度解读CSS工程化实践成果
- 腾讯微下载
- 开发者最讨厌的编程语言:Perl 名列第一,PHP、Objective-C 和 Ruby 都在其中
- msf学习笔记(3)
- Android Studio3中文输入法卡顿,不显示问题