zoukankan      html  css  js  c++  java
  • Unity3D 选择焦点切换

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using UnityEngine;
    using UnityEngine.EventSystems;
    
    namespace Assets.Scripts.Models
    {
        /// <summary>
        /// 该类用于登录页面中用户名、密码框的切换
        /// </summary>
        class MyTabClass : MonoBehaviour
        {
            /// <summary>
            /// 需要切换的元素
            /// </summary>
            public GameObject UserNameObj,PasswordObj;
    
            private EventSystem system;
    
            private void Start()
            {
                system = EventSystem.current;//获取当前场景EventSystem
            }
            private void Update()
            {
                if (UserNameObj != null && PasswordObj != null) {
                    if (Input.GetKeyDown(KeyCode.Tab)) {//按下Tab键,如果用户名没被选中,就选择用户名,否则选择密码框
                        if (system.currentSelectedGameObject != UserNameObj)
                        {
                            system.SetSelectedGameObject(UserNameObj, new BaseEventData(system));
                        }
                        else {
                            system.SetSelectedGameObject(PasswordObj, new BaseEventData(system));
                        }
                    }
                }
            }
    
        }
    }
    

      

  • 相关阅读:
    2020软件工程作业02
    自我介绍
    Requests的使用
    爬虫基本原理
    2019春总结作业
    十二周作业
    十一周作业
    第十周作业
    intellij idea 的全局搜索快捷键方法
    Oracle多表关联
  • 原文地址:https://www.cnblogs.com/nick-jd/p/12420506.html
Copyright © 2011-2022 走看看