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));
                        }
                    }
                }
            }
    
        }
    }
    

      

  • 相关阅读:
    130被围绕的区域
    695岛屿的最大面积
    200岛屿数量
    5314跳跃游戏IV
    375猜数字大小II
    464我能赢吗
    486预测赢家
    877石子游戏
    1000合并石头的最低成本
    5329数组大小减半
  • 原文地址:https://www.cnblogs.com/nick-jd/p/12420506.html
Copyright © 2011-2022 走看看