HomeView.cs 4.7 KB

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