HomeView.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. if (BluetoothAim.ins.status == BluetoothStatusEnum.Connect) {
  59. btnConnectBow.GetComponent<Button>().enabled = true;
  60. } else {
  61. btnConnectBow.GetComponent<Button>().enabled = false;
  62. }
  63. }
  64. if (BluetoothShoot.ins && arrowStatus != BluetoothShoot.ins.status) {
  65. arrowStatus = BluetoothShoot.ins.status;
  66. (int textID, Color color) = BluetoothStatus.GetStatusInfo(BluetoothShoot.ins.status);
  67. btnConnectArrow.GetComponentInChildren<TextAutoLanguage>().SetText(textID);
  68. btnConnectArrow.GetComponentInChildren<Text>().color = color;
  69. if (BluetoothShoot.ins.status == BluetoothStatusEnum.Connect) {
  70. btnConnectArrow.GetComponent<Button>().enabled = true;
  71. } else {
  72. btnConnectArrow.GetComponent<Button>().enabled = false;
  73. }
  74. }
  75. }
  76. public void GoTo(string target) {
  77. AudioMgr.ins.PlayBtn();
  78. switch (target)
  79. {
  80. case "闯关":
  81. // GameObject.Instantiate(Resources.Load<GameObject>("Prefabs/Views/ChallengeReadyView"), Vector3.zero, new Quaternion());
  82. break;
  83. case "限时":
  84. GameMgr.gameType = 1;
  85. SceneManager.LoadScene("Game", LoadSceneMode.Single);
  86. break;
  87. case "对战":
  88. GameObject.Instantiate(Resources.Load<GameObject>("Prefabs/Views/RoleSelectView"));
  89. break;
  90. case "教程":
  91. GameObject.Instantiate(Resources.Load<GameObject>("Prefabs/Views/CourseView"), Vector3.zero, new Quaternion());
  92. break;
  93. case "设置":
  94. GameObject.Instantiate(Resources.Load<GameObject>("Prefabs/Views/SetUpView"), Vector3.zero, new Quaternion());
  95. break;
  96. case "我的":
  97. GameObject.Instantiate(Resources.Load<GameObject>("Prefabs/Views/MeView"), Vector3.zero, new Quaternion());
  98. break;
  99. case "设备":
  100. GameObject.Instantiate(Resources.Load<GameObject>("Prefabs/Views/DeviceView"), Vector3.zero, new Quaternion());
  101. break;
  102. case "商城":
  103. GameObject.Instantiate(Resources.Load<GameObject>("Prefabs/Views/ShopView"), Vector3.zero, new Quaternion());
  104. break;
  105. case "退出":
  106. Application.Quit();
  107. break;
  108. default:
  109. break;
  110. }
  111. }
  112. }