HomeView.cs 6.1 KB

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