1.在Hierarchy面板创建能被选中的UI(Button、InputField等)。

2.在Canvas上创建C#脚本 TabCutPichon。

3.编写脚本。

 using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems; public class TabCutPitchOn : MonoBehaviour
{
// 得到EventSystem组件
private EventSystem system;
// 字典:key 游戏物体编号,游戏物体
private Dictionary<int,GameObject> dicObj;
// 用于存储得到的字典的索引
private int index; void Start ()
{
// 初始化字段
system = EventSystem.current;
dicObj = new Dictionary<int, GameObject> ();
index = ;
// 给字典赋值
for (int i = ; i < transform.childCount; i++) {
dicObj.Add (i, transform.GetChild (i).gameObject);
}
// 得到字典中对应索引的游戏物体
GameObject obj;
dicObj.TryGetValue (index, out obj);
// 设置第一个可交互的UI为高亮状态
system.SetSelectedGameObject (obj, new BaseEventData (system));
} void Update ()
{
// 当有 UI 高亮(得到高亮的UI,不为空)并且 按下Tab键
if (system.currentSelectedGameObject != null && Input.GetKeyDown (KeyCode.Tab)) {
// 得到当前高亮状态的 UI 物体
GameObject hightedObj = system.currentSelectedGameObject;
// 看是场景中第几个物体
foreach (KeyValuePair<int,GameObject> item in dicObj) {
if (item.Value == hightedObj) {
index = item.Key + ;
// 超出索引 将Index归零
if (index == dicObj.Count) {
index = ;
}
break;
}
}
// 得到对应索引的游戏物体
GameObject obj;
dicObj.TryGetValue (index, out obj);
// 使得到的游戏物体高亮
system.SetSelectedGameObject (obj, new BaseEventData (system));
}
}
}

最新文章

  1. python读取excel一例-------从工资表逐行提取信息
  2. 【读书笔记《Bootstrap 实战》】5.电子商务网站
  3. mybatis报invalue types()错误
  4. Android 获取系统的联系人
  5. Android学习笔记——download
  6. 一台服务器发布多个tomcat并注册服务名办法
  7. LeetCode OJ-- Sort List **@
  8. eclipse,myeclipse开发环境下,maven远程部署到tomcat7服务器(图文)
  9. setcookie各个参数详解
  10. 过滤3个字节以上的utf-8字符
  11. 【JavsScript】推荐五款流行的JavaScript模板引擎
  12. (转)[转]大数据时代的 9 大Key-Value存储数据库
  13. Windows Phone 8初学者开发—第23部分:测试并向应用商店提交
  14. MVC 编程模型及其变种
  15. ASP.NET Core中使用GraphQL - 第一章 Hello World
  16. yii2.0 url美化-apache服务器
  17. SpringBoot 之基础学习篇.
  18. 一次有趣的ant-design与后端数据交互的使用
  19. Golang 端口复用测试
  20. QQ检测登陆及QQ协议

热门文章

  1. C#提取html中的汉字
  2. jzoj5195. 【NOIP2017提高组模拟7.3】A(递推,打表)
  3. 【解决】docker 容器中 consul集群问题处理
  4. httpd的prefork、worker、event
  5. Asp.net 自定义CustomerSession 存放到Redis中
  6. Java写Excel(不生成实体文件,写为流的形式)
  7. 11 非阻塞套接字与IO多路复用(进阶)
  8. python 排列组合
  9. rails中如何在a标签中添加其他标签
  10. 模块的使用与orm简介