HomeView.cs 4.8 KB

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