HomeView.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. }
  21. void FixedUpdate()
  22. {
  23. UpdateBtnForConnect();
  24. }
  25. public void RenderNameOrGender() {
  26. nickNameText.text = LoginMgr.myUserInfo.nickname;
  27. genders[LoginMgr.myUserInfo.gender == 2 ? 1 : 0].SetActive(true);
  28. genders[LoginMgr.myUserInfo.gender == 2 ? 0 : 1].SetActive(false);
  29. LayoutRebuilder.ForceRebuildLayoutImmediate(nickNameText.transform.parent.GetComponent<RectTransform>());
  30. }
  31. void InitBtnForConnect()
  32. {
  33. btnConnectBow.GetComponent<Button>().onClick.AddListener(delegate() {
  34. BluetoothAim.ins.Connect();
  35. });
  36. btnConnectArrow.GetComponent<Button>().onClick.AddListener(delegate() {
  37. BluetoothShoot.ins.Connect();
  38. });
  39. }
  40. BluetoothStatusEnum bowStatus;
  41. BluetoothStatusEnum arrowStatus;
  42. void UpdateBtnForConnect() {
  43. if (BluetoothAim.ins && bowStatus != BluetoothAim.ins.status) {
  44. bowStatus = BluetoothAim.ins.status;
  45. (int textID, Color color) = BluetoothStatus.GetStatusInfo(BluetoothAim.ins.status);
  46. btnConnectBow.GetComponentInChildren<TextAutoLanguage>().SetText(textID);
  47. btnConnectBow.GetComponentInChildren<Text>().color = color;
  48. if (BluetoothAim.ins.status == BluetoothStatusEnum.Connect) {
  49. btnConnectBow.GetComponent<Button>().enabled = true;
  50. } else {
  51. btnConnectBow.GetComponent<Button>().enabled = false;
  52. }
  53. }
  54. if (BluetoothShoot.ins && arrowStatus != BluetoothShoot.ins.status) {
  55. arrowStatus = BluetoothShoot.ins.status;
  56. (int textID, Color color) = BluetoothStatus.GetStatusInfo(BluetoothShoot.ins.status);
  57. btnConnectArrow.GetComponentInChildren<TextAutoLanguage>().SetText(textID);
  58. btnConnectArrow.GetComponentInChildren<Text>().color = color;
  59. if (BluetoothShoot.ins.status == BluetoothStatusEnum.Connect) {
  60. btnConnectArrow.GetComponent<Button>().enabled = true;
  61. } else {
  62. btnConnectArrow.GetComponent<Button>().enabled = false;
  63. }
  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. default:
  96. break;
  97. }
  98. }
  99. }