HomeView.cs 5.9 KB

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