HomeView.cs 6.0 KB

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