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

      

  • 相关阅读:
    python入门-函数(二)
    python入门-函数(一)
    python入门-WHILE循环
    python入门-用户输入
    python入门-字典
    Spring Security授权 AccessDecisionManager
    Java的性能优化
    datahub
    vbs mytest
    spring发布和接收定制的事件(spring事件传播)
  • 原文地址:https://www.cnblogs.com/nick-jd/p/12420506.html
Copyright © 2020-2023  润新知