HomeView.cs 5.7 KB

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