HomeView.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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] Image myAvatarSprite;
  10. [SerializeField] Text nickNameText;
  11. [SerializeField] GameObject[] genders;
  12. [SerializeField] GameObject btnConnectBow;
  13. [SerializeField] GameObject btnConnectArrow;
  14. [SerializeField] GameObject friendTip;
  15. public static HomeView ins;
  16. void Start()
  17. {
  18. ins = this;
  19. BluetoothHolder.Init();
  20. AudioMgr.Init();
  21. if (ShootCheck.ins) ShootCheck.ins.AdjustNormalOrHightMode();
  22. InitBtnForConnect();
  23. if (LoginMgr.myUserInfo.id > 0) {
  24. RenderNameOrGender();
  25. RenderMyAvatarSprite();
  26. RenderDeviceNames();
  27. }
  28. }
  29. void FixedUpdate()
  30. {
  31. UpdateBtnForConnect();
  32. }
  33. void Update() {
  34. if (UserPlayer.ins != null) {
  35. if (UserPlayer.ins.tempData.hasFriendRequest && !friendTip.activeSelf) {
  36. friendTip.SetActive(true);
  37. }
  38. else if (!UserPlayer.ins.tempData.hasFriendRequest && friendTip.activeSelf) {
  39. friendTip.SetActive(false);
  40. }
  41. }
  42. }
  43. public void RenderNameOrGender() {
  44. nickNameText.text = LoginMgr.myUserInfo.nickname;
  45. genders[LoginMgr.myUserInfo.gender == 2 ? 1 : 0].SetActive(true);
  46. genders[LoginMgr.myUserInfo.gender == 2 ? 0 : 1].SetActive(false);
  47. LayoutRebuilder.ForceRebuildLayoutImmediate(nickNameText.transform.parent.GetComponent<RectTransform>());
  48. }
  49. public void RenderMyAvatarSprite() {
  50. myAvatarSprite.sprite = RoleMgr.GetAvatar(LoginMgr.myUserInfo.avatarID);
  51. }
  52. public void RenderDeviceNames()
  53. {
  54. try {
  55. (DeviceInfo bowInfo, DeviceInfo arrowInfo) = DeviceMgr.ins.GetCurrentBowArrowInfo();
  56. // this.transform.Find("ShowBow/Text").GetComponent<TextAutoLanguage>().SetText(bowInfo.config.name);
  57. this.transform.Find("ShowBow/Text").GetComponent<TextAutoLanguage>().SetText(200000);
  58. this.transform.Find("ShowArrow/Text").GetComponent<TextAutoLanguage>().SetText(arrowInfo.config.name);
  59. } catch (System.Exception) {}
  60. }
  61. void InitBtnForConnect()
  62. {
  63. btnConnectBow.GetComponent<Button>().onClick.AddListener(delegate() {
  64. BluetoothAim.ins.DoConnect();
  65. });
  66. btnConnectArrow.GetComponent<Button>().onClick.AddListener(delegate() {
  67. BluetoothShoot.ins.DoConnect();
  68. });
  69. }
  70. BluetoothStatusEnum bowStatus;
  71. BluetoothStatusEnum arrowStatus;
  72. void UpdateBtnForConnect() {
  73. if (BluetoothAim.ins && bowStatus != BluetoothAim.ins.status) {
  74. bowStatus = BluetoothAim.ins.status;
  75. (int textID, Color color) = BluetoothStatus.GetStatusInfo(BluetoothAim.ins.status);
  76. btnConnectBow.GetComponentInChildren<TextAutoLanguage>().SetText(textID);
  77. btnConnectBow.GetComponentInChildren<Text>().color = color;
  78. }
  79. if (BluetoothShoot.ins && arrowStatus != BluetoothShoot.ins.status) {
  80. arrowStatus = BluetoothShoot.ins.status;
  81. (int textID, Color color) = BluetoothStatus.GetStatusInfo(BluetoothShoot.ins.status);
  82. btnConnectArrow.GetComponentInChildren<TextAutoLanguage>().SetText(textID);
  83. btnConnectArrow.GetComponentInChildren<Text>().color = color;
  84. }
  85. }
  86. public void GoTo(string target) {
  87. AudioMgr.ins.PlayBtn();
  88. switch (target)
  89. {
  90. case "开始游戏":
  91. if (!BluetoothStatus.IsAllConnected()) {
  92. PopupMgr.ins.ShowTip("请先连接设备");
  93. return;
  94. }
  95. GameObject.Instantiate(GameObject.Find("WindowViews").transform.Find("GameStartView").gameObject).SetActive(true);
  96. break;
  97. case "联机游戏":
  98. if (!BluetoothStatus.IsAllConnected()) {
  99. PopupMgr.ins.ShowTip("请先连接设备");
  100. return;
  101. }
  102. GlobalDataTemp.pkMatchType = PKMatchType.OnlinePK;
  103. GameObject.Instantiate(GameObject.Find("WindowViews").transform.Find("PKGameOptionView").gameObject).SetActive(true);
  104. break;
  105. case "好友":
  106. GameObject.Instantiate(Resources.Load<GameObject>("Prefabs/Views/FriendView"));
  107. break;
  108. case "排行磅":
  109. GameObject.Instantiate(Resources.Load<GameObject>("Prefabs/Views/RankView"));
  110. break;
  111. case "对战":
  112. GameObject.Instantiate(Resources.Load<GameObject>("Prefabs/Views/RoleSelectView"));
  113. break;
  114. case "教程":
  115. GameObject.Instantiate(Resources.Load<GameObject>("Prefabs/Views/CourseView"), Vector3.zero, new Quaternion());
  116. break;
  117. case "我的":
  118. GameObject.Instantiate(Resources.Load<GameObject>("Prefabs/Views/MeView"), Vector3.zero, new Quaternion());
  119. break;
  120. case "设备":
  121. GameObject.Instantiate(Resources.Load<GameObject>("Prefabs/Views/DeviceView"), Vector3.zero, new Quaternion());
  122. break;
  123. case "商城":
  124. GameObject.Instantiate(Resources.Load<GameObject>("Prefabs/Views/ShopView"), Vector3.zero, new Quaternion());
  125. break;
  126. default:
  127. break;
  128. }
  129. }
  130. }