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