| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- using UnityEngine.EventSystems;
- public class GameMenuView : MonoBehaviour
- {
- [SerializeField] GameObject funcView;
- Button[] funcItemButtons;
- [SerializeField] Text keyCodeText;
- void Awake()
- {
- funcItemButtons = funcView.transform.Find("Items").GetComponentsInChildren<Button>();
- for (int i = 0; i < funcItemButtons.Length; i++)
- {
- int id = i;
- funcItemButtons[i].onClick.AddListener(delegate() {
- SelectItem(id, true);
- ConfirmItem(id);
- });
- }
- SelectItem(0, true);
- }
- void Update()
- {
- if (Input.GetKeyDown(KeyCode.UpArrow))
- {
- SelectItem(-1);
- AudioMgr.ins.PlayBtn();
- }
- if (Input.GetKeyDown(KeyCode.DownArrow))
- {
- SelectItem(+1);
- AudioMgr.ins.PlayBtn();
- }
- if (Input.GetKeyDown(KeyCode.JoystickButton0) || Input.GetKeyDown(KeyCode.Return))
- {
- if (funcView.activeSelf) {
- ConfirmItem(funcItemIndex);
- }
- if (recordItemIns && recordItemOkBtn.interactable) {
- recordItemOkBtn.onClick.Invoke();
- }
- }
- if (Input.GetKeyDown(KeyCode.Escape))
- {
- if (recordItemIns && recordItemBackBtn.interactable) {
- recordItemBackBtn.onClick.Invoke();
- }
- }
- }
- void OnGUI()
- {
- if (Input.anyKeyDown)
- {
- Event e = Event.current;
- if (e.isKey)
- {
- keyCodeText.text = string.Format("按下的键值:[{0}]", e.character);
- }
- }
- }
- void ShowFuncView(bool active)
- {
- funcView.SetActive(active);
- }
- int funcItemIndex = 0;
- void SelectItem(int deltaIndex, bool isFixed = false)
- {
- if (!funcView.activeSelf) return;
- funcItemIndex += deltaIndex;
- if (funcItemIndex < 0) {
- funcItemIndex = funcItemButtons.Length - 1;
- } else if (funcItemIndex >= funcItemButtons.Length) {
- funcItemIndex = 0;
- }
- if (isFixed) funcItemIndex = deltaIndex;
- for (int i = 0; i < funcItemButtons.Length; i++) {
- funcItemButtons[i].GetComponentInChildren<Image>().color = i == funcItemIndex ? Color.yellow : Color.white;
- Text ttt = funcItemButtons[i].GetComponentInChildren<Text>();
- if (ttt) ttt.color = i == funcItemIndex ? Color.yellow : Color.white;
-
- }
- }
- void ConfirmItem(int id)
- {
- if (!funcView.activeSelf) return;
- AudioMgr.ins.PlayBtn();
- switch (id)
- {
- case 1:
- ShowFuncView(false);
- GameObject v1 = DeviceCalibrateView.Create(DeviceCalibrateItem.Gyr);
- RecordItem(v1);
- break;
- case 2:
- ShowFuncView(false);
- GameObject v2 = DeviceCalibrateView.Create(DeviceCalibrateItem.Mag);
- RecordItem(v2);
- break;
- case 3:
- AutoResetView.DoIdentity();
- break;
- case 4:
- // if (LoginMgr.myUserInfo.arrowAccValue == 16) {
- // LoginMgr.myUserInfo.arrowAccValue = 64;
- // } else {
- // LoginMgr.myUserInfo.arrowAccValue = 16;
- // }
- // LoginMgr.myUserInfo.Save();
- // RenderArrowAcc();
- break;
- case 0:
- Application.Quit();
- break;
- }
- }
- // public void RenderArrowAcc()
- // {
- // funcItemButtons[4].GetComponentInChildren<Text>().text = LoginMgr.myUserInfo.arrowAccValue + "G使用中";
- // }
- GameObject recordItemIns;
- Button recordItemOkBtn;
- Button recordItemBackBtn;
- void RecordItem(GameObject itemIns)
- {
- ClearRecordItem();
- recordItemIns = itemIns;
- (recordItemOkBtn, recordItemBackBtn) = itemIns.GetComponent<DeviceCalibrateView>().GetInterfaceBtns();
- recordItemBackBtn.onClick.AddListener(delegate() {
- ShowFuncView(true);
- });
- }
- void ClearRecordItem()
- {
- if (recordItemIns) Destroy(recordItemIns);
- }
- }
|