HomeView.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. if (GameObject.Find("Bluetooth") == null) {
  17. GameObject bluetooth = new GameObject("Bluetooth");
  18. // bluetooth.AddComponent<ShootCheck>();
  19. // bluetooth.AddComponent<BluetoothBC>();
  20. // bluetooth.AddComponent<BluetoothD>();
  21. DontDestroyOnLoad(bluetooth);
  22. }
  23. if (!BluetoothHolder.ins) {
  24. GameObject bluetoothHolder = Resources.Load<GameObject>("Prefabs/BluetoothHolder");
  25. GameObject.Instantiate(bluetoothHolder);
  26. }
  27. AudioMgr.init();
  28. RenderNameOrGender();
  29. InitBtnForConnect();
  30. }
  31. void FixedUpdate()
  32. {
  33. UpdateBtnForConnect();
  34. }
  35. public void RenderNameOrGender() {
  36. nickNameText.text = LoginMgr.myUserInfo.nickname;
  37. genders[LoginMgr.myUserInfo.gender == "男" ? 0 : 1].SetActive(true);
  38. genders[LoginMgr.myUserInfo.gender == "男" ? 1 : 0].SetActive(false);
  39. LayoutRebuilder.ForceRebuildLayoutImmediate(nickNameText.transform.parent.GetComponent<RectTransform>());
  40. }
  41. void InitBtnForConnect()
  42. {
  43. btnConnectBow.GetComponent<Button>().onClick.AddListener(delegate() {
  44. BluetoothAim.ins.Connect();
  45. });
  46. btnConnectArrow.GetComponent<Button>().onClick.AddListener(delegate() {
  47. BluetoothShoot.ins.Connect();
  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. (string text1, Color color1) = BluetoothStatus.GetStatusInfo(BluetoothAim.ins.status);
  56. btnConnectBow.GetComponentInChildren<Text>().text = text1;
  57. btnConnectBow.GetComponentInChildren<Text>().color = color1;
  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. (string text2, Color color2) = BluetoothStatus.GetStatusInfo(BluetoothShoot.ins.status);
  67. btnConnectArrow.GetComponentInChildren<Text>().text = text2;
  68. btnConnectArrow.GetComponentInChildren<Text>().color = color2;
  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. default:
  106. break;
  107. }
  108. }
  109. }