HomeView.cs 4.6 KB

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