HomeView.cs 4.2 KB

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