HomeView.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using UnityEngine.SceneManagement;
  6. public class HomeView : MonoBehaviour
  7. {
  8. [SerializeField] Text nickNameText;
  9. [SerializeField] GameObject[] genders;
  10. [SerializeField] GameObject btnConnectBow;
  11. [SerializeField] GameObject btnConnectArrow;
  12. public static HomeView ins;
  13. void Start()
  14. {
  15. ins = this;
  16. BluetoothHolder.Init();
  17. AudioMgr.Init();
  18. if (ShootCheck.ins) ShootCheck.ins.AdjustNormalOrHightMode();
  19. RenderNameOrGender();
  20. InitBtnForConnect();
  21. RenderDeviceNames();
  22. }
  23. void FixedUpdate()
  24. {
  25. UpdateBtnForConnect();
  26. }
  27. public void RenderNameOrGender() {
  28. nickNameText.text = LoginMgr.myUserInfo.nickname;
  29. genders[LoginMgr.myUserInfo.gender == 2 ? 1 : 0].SetActive(true);
  30. genders[LoginMgr.myUserInfo.gender == 2 ? 0 : 1].SetActive(false);
  31. LayoutRebuilder.ForceRebuildLayoutImmediate(nickNameText.transform.parent.GetComponent<RectTransform>());
  32. }
  33. public void RenderDeviceNames()
  34. {
  35. try {
  36. (DeviceInfo bowInfo, DeviceInfo arrowInfo) = DeviceMgr.ins.GetCurrentBowArrowInfo();
  37. this.transform.Find("ShowBow/Text").GetComponent<TextAutoLanguage>().SetText(bowInfo.config.name);
  38. this.transform.Find("ShowArrow/Text").GetComponent<TextAutoLanguage>().SetText(arrowInfo.config.name);
  39. } catch (System.Exception) {}
  40. }
  41. void InitBtnForConnect()
  42. {
  43. btnConnectBow.GetComponent<Button>().onClick.AddListener(delegate() {
  44. BluetoothAim.ins.DoConnect();
  45. });
  46. btnConnectArrow.GetComponent<Button>().onClick.AddListener(delegate() {
  47. BluetoothShoot.ins.DoConnect();
  48. });
  49. }
  50. BluetoothStatusEnum bowStatus;
  51. BluetoothStatusEnum arrowStatus;
  52. void UpdateBtnForConnect() {
  53. if (BluetoothAim.ins && bowStatus != BluetoothAim.ins.status) {
  54. bowStatus = BluetoothAim.ins.status;
  55. (int textID, Color color) = BluetoothStatus.GetStatusInfo(BluetoothAim.ins.status);
  56. btnConnectBow.GetComponentInChildren<TextAutoLanguage>().SetText(textID);
  57. btnConnectBow.GetComponentInChildren<Text>().color = color;
  58. }
  59. if (BluetoothShoot.ins && arrowStatus != BluetoothShoot.ins.status) {
  60. arrowStatus = BluetoothShoot.ins.status;
  61. (int textID, Color color) = BluetoothStatus.GetStatusInfo(BluetoothShoot.ins.status);
  62. btnConnectArrow.GetComponentInChildren<TextAutoLanguage>().SetText(textID);
  63. btnConnectArrow.GetComponentInChildren<Text>().color = color;
  64. }
  65. }
  66. public void GoTo(string target) {
  67. AudioMgr.ins.PlayBtn();
  68. switch (target)
  69. {
  70. case "闯关":
  71. // GameObject.Instantiate(Resources.Load<GameObject>("Prefabs/Views/ChallengeReadyView"), Vector3.zero, new Quaternion());
  72. break;
  73. case "限时":
  74. GameMgr.gameType = 1;
  75. SceneManager.LoadScene("Game", LoadSceneMode.Single);
  76. break;
  77. case "对战":
  78. GameObject.Instantiate(Resources.Load<GameObject>("Prefabs/Views/RoleSelectView"));
  79. break;
  80. case "教程":
  81. GameObject.Instantiate(Resources.Load<GameObject>("Prefabs/Views/CourseView"), Vector3.zero, new Quaternion());
  82. break;
  83. case "设置":
  84. GameObject.Instantiate(Resources.Load<GameObject>("Prefabs/Views/SetUpView"), Vector3.zero, new Quaternion());
  85. break;
  86. case "我的":
  87. GameObject.Instantiate(Resources.Load<GameObject>("Prefabs/Views/MeView"), Vector3.zero, new Quaternion());
  88. break;
  89. case "设备":
  90. GameObject.Instantiate(Resources.Load<GameObject>("Prefabs/Views/DeviceView"), Vector3.zero, new Quaternion());
  91. break;
  92. case "商城":
  93. GameObject.Instantiate(Resources.Load<GameObject>("Prefabs/Views/ShopView"), Vector3.zero, new Quaternion());
  94. break;
  95. case "退出":
  96. Application.Quit();
  97. break;
  98. default:
  99. break;
  100. }
  101. }
  102. }