HomeView.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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("ShowArrow/Text").GetComponent<TextAutoLanguage>().SetText(arrowInfo.config.name);
  45. } catch (System.Exception) {}
  46. }
  47. void InitBtnForConnect()
  48. {
  49. btnConnectBow.GetComponent<Button>().onClick.AddListener(delegate() {
  50. BluetoothAim.ins.DoConnect();
  51. });
  52. btnConnectArrow.GetComponent<Button>().onClick.AddListener(delegate() {
  53. BluetoothShoot.ins.DoConnect();
  54. });
  55. }
  56. BluetoothStatusEnum bowStatus;
  57. BluetoothStatusEnum arrowStatus;
  58. void UpdateBtnForConnect() {
  59. if (BluetoothAim.ins && bowStatus != BluetoothAim.ins.status) {
  60. bowStatus = BluetoothAim.ins.status;
  61. (int textID, Color color) = BluetoothStatus.GetStatusInfo(BluetoothAim.ins.status);
  62. btnConnectBow.GetComponentInChildren<TextAutoLanguage>().SetText(textID);
  63. btnConnectBow.GetComponentInChildren<Text>().color = color;
  64. }
  65. if (BluetoothShoot.ins && arrowStatus != BluetoothShoot.ins.status) {
  66. arrowStatus = BluetoothShoot.ins.status;
  67. (int textID, Color color) = BluetoothStatus.GetStatusInfo(BluetoothShoot.ins.status);
  68. btnConnectArrow.GetComponentInChildren<TextAutoLanguage>().SetText(textID);
  69. btnConnectArrow.GetComponentInChildren<Text>().color = color;
  70. }
  71. }
  72. public void GoTo(string target) {
  73. AudioMgr.ins.PlayBtn();
  74. switch (target)
  75. {
  76. case "开始游戏":
  77. GameObject.Instantiate(GameObject.Find("WindowViews").transform.Find("GameStartView").gameObject).SetActive(true);
  78. break;
  79. case "联机游戏":
  80. GlobalData.pkMatchType = PKMatchType.OnlinePK;
  81. GameObject.Instantiate(GameObject.Find("WindowViews").transform.Find("PKGameOptionView").gameObject).SetActive(true);
  82. break;
  83. case "好友":
  84. break;
  85. case "排行磅":
  86. break;
  87. case "对战":
  88. GameObject.Instantiate(Resources.Load<GameObject>("Prefabs/Views/RoleSelectView"));
  89. break;
  90. case "教程":
  91. GameObject.Instantiate(Resources.Load<GameObject>("Prefabs/Views/CourseView"), Vector3.zero, new Quaternion());
  92. break;
  93. case "设置":
  94. GameObject.Instantiate(Resources.Load<GameObject>("Prefabs/Views/SetUpView"), 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. case "退出":
  106. Application.Quit();
  107. break;
  108. default:
  109. break;
  110. }
  111. }
  112. }