HomeView.cs 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using UnityEngine.SceneManagement;
  6. public class HomeView : MonoBehaviour
  7. {
  8. [SerializeField] Text nickNameText;
  9. [SerializeField] GameObject[] genders;
  10. public static HomeView ins;
  11. void Start()
  12. {
  13. ins = this;
  14. if (GameObject.Find("Bluetooth") == null) {
  15. GameObject bluetooth = new GameObject("Bluetooth");
  16. // bluetooth.AddComponent<ShootCheck>();
  17. // bluetooth.AddComponent<BluetoothBC>();
  18. // bluetooth.AddComponent<BluetoothD>();
  19. DontDestroyOnLoad(bluetooth);
  20. }
  21. if (!BluetoothHolder.ins) {
  22. GameObject bluetoothHolder = Resources.Load<GameObject>("Prefabs/BluetoothHolder");
  23. GameObject.Instantiate(bluetoothHolder);
  24. }
  25. AudioMgr.init();
  26. RenderNameOrGender();
  27. }
  28. public void RenderNameOrGender() {
  29. nickNameText.text = LoginMgr.myUserInfo.nickname;
  30. genders[LoginMgr.myUserInfo.gender == "男" ? 0 : 1].SetActive(true);
  31. genders[LoginMgr.myUserInfo.gender == "男" ? 1 : 0].SetActive(false);
  32. LayoutRebuilder.ForceRebuildLayoutImmediate(nickNameText.transform.parent.GetComponent<RectTransform>());
  33. }
  34. public void GoTo(string target) {
  35. AudioMgr.ins.PlayBtn();
  36. switch (target)
  37. {
  38. case "闯关":
  39. // GameObject.Instantiate(Resources.Load<GameObject>("Prefabs/Views/ChallengeReadyView"), Vector3.zero, new Quaternion());
  40. break;
  41. case "限时":
  42. GameMgr.gameType = 1;
  43. SceneManager.LoadScene("Game", LoadSceneMode.Single);
  44. break;
  45. case "对战":
  46. GameMgr.gameType = 2;
  47. SceneManager.LoadScene("Game", LoadSceneMode.Single);
  48. break;
  49. case "教程":
  50. GameObject.Instantiate(Resources.Load<GameObject>("Prefabs/Views/CourseView"), Vector3.zero, new Quaternion());
  51. break;
  52. case "设置":
  53. GameObject.Instantiate(Resources.Load<GameObject>("Prefabs/Views/SetUpView"), Vector3.zero, new Quaternion());
  54. break;
  55. case "我的":
  56. GameObject.Instantiate(Resources.Load<GameObject>("Prefabs/Views/MeView"), Vector3.zero, new Quaternion());
  57. break;
  58. case "设备":
  59. GameObject.Instantiate(Resources.Load<GameObject>("Prefabs/Views/DeviceView"), Vector3.zero, new Quaternion());
  60. break;
  61. case "商城":
  62. GameObject.Instantiate(Resources.Load<GameObject>("Prefabs/Views/ShopView"), Vector3.zero, new Quaternion());
  63. break;
  64. default:
  65. break;
  66. }
  67. }
  68. }