| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- using UnityEngine.SceneManagement;
- public class HomeView : MonoBehaviour
- {
- [SerializeField] Text nickNameText;
- [SerializeField] GameObject[] genders;
- [SerializeField] GameObject btnConnectBow;
- [SerializeField] GameObject btnConnectArrow;
- public static HomeView ins;
- void Start()
- {
- ins = this;
- BluetoothHolder.Init();
- AudioMgr.Init();
- if (ShootCheck.ins) ShootCheck.ins.AdjustNormalOrHightMode();
- RenderNameOrGender();
- InitBtnForConnect();
- RenderDeviceNames();
- }
- void FixedUpdate()
- {
- UpdateBtnForConnect();
- }
- public void RenderNameOrGender() {
- nickNameText.text = LoginMgr.myUserInfo.nickname;
- genders[LoginMgr.myUserInfo.gender == 2 ? 1 : 0].SetActive(true);
- genders[LoginMgr.myUserInfo.gender == 2 ? 0 : 1].SetActive(false);
- LayoutRebuilder.ForceRebuildLayoutImmediate(nickNameText.transform.parent.GetComponent<RectTransform>());
- }
- public void RenderDeviceNames()
- {
- try {
- (DeviceInfo bowInfo, DeviceInfo arrowInfo) = DeviceMgr.ins.GetCurrentBowArrowInfo();
- this.transform.Find("ShowBow/Text").GetComponent<TextAutoLanguage>().SetText(bowInfo.config.name);
- this.transform.Find("ShowArrow/Text").GetComponent<TextAutoLanguage>().SetText(arrowInfo.config.name);
- } catch (System.Exception) {}
- }
- void InitBtnForConnect()
- {
- btnConnectBow.GetComponent<Button>().onClick.AddListener(delegate() {
- BluetoothAim.ins.DoConnect();
- });
- btnConnectArrow.GetComponent<Button>().onClick.AddListener(delegate() {
- BluetoothShoot.ins.DoConnect();
- });
- }
- BluetoothStatusEnum bowStatus;
- BluetoothStatusEnum arrowStatus;
- void UpdateBtnForConnect() {
- if (BluetoothAim.ins && bowStatus != BluetoothAim.ins.status) {
- bowStatus = BluetoothAim.ins.status;
- (int textID, Color color) = BluetoothStatus.GetStatusInfo(BluetoothAim.ins.status);
- btnConnectBow.GetComponentInChildren<TextAutoLanguage>().SetText(textID);
- btnConnectBow.GetComponentInChildren<Text>().color = color;
- if (BluetoothAim.ins.status == BluetoothStatusEnum.Connect) {
- btnConnectBow.GetComponent<Button>().enabled = true;
- } else {
- btnConnectBow.GetComponent<Button>().enabled = false;
- }
- }
- if (BluetoothShoot.ins && arrowStatus != BluetoothShoot.ins.status) {
- arrowStatus = BluetoothShoot.ins.status;
- (int textID, Color color) = BluetoothStatus.GetStatusInfo(BluetoothShoot.ins.status);
- btnConnectArrow.GetComponentInChildren<TextAutoLanguage>().SetText(textID);
- btnConnectArrow.GetComponentInChildren<Text>().color = color;
- if (BluetoothShoot.ins.status == BluetoothStatusEnum.Connect) {
- btnConnectArrow.GetComponent<Button>().enabled = true;
- } else {
- btnConnectArrow.GetComponent<Button>().enabled = false;
- }
- }
- }
- public void GoTo(string target) {
- AudioMgr.ins.PlayBtn();
- switch (target)
- {
- case "闯关":
- // GameObject.Instantiate(Resources.Load<GameObject>("Prefabs/Views/ChallengeReadyView"), Vector3.zero, new Quaternion());
- break;
- case "限时":
- GameMgr.gameType = 1;
- SceneManager.LoadScene("Game", LoadSceneMode.Single);
- break;
- case "对战":
- GameObject.Instantiate(Resources.Load<GameObject>("Prefabs/Views/RoleSelectView"));
- break;
- case "教程":
- GameObject.Instantiate(Resources.Load<GameObject>("Prefabs/Views/CourseView"), Vector3.zero, new Quaternion());
- break;
- case "设置":
- GameObject.Instantiate(Resources.Load<GameObject>("Prefabs/Views/SetUpView"), Vector3.zero, new Quaternion());
- break;
- case "我的":
- GameObject.Instantiate(Resources.Load<GameObject>("Prefabs/Views/MeView"), Vector3.zero, new Quaternion());
- break;
- case "设备":
- GameObject.Instantiate(Resources.Load<GameObject>("Prefabs/Views/DeviceView"), Vector3.zero, new Quaternion());
- break;
- case "商城":
- GameObject.Instantiate(Resources.Load<GameObject>("Prefabs/Views/ShopView"), Vector3.zero, new Quaternion());
- break;
- case "退出":
- Application.Quit();
- break;
- default:
- break;
- }
- }
- }
|