ThreeDNav.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. using DG.Tweening;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using UnityEngine.UI;
  6. using UnityAsync;
  7. using WaitUntil = UnityAsync.WaitUntil;
  8. public class ThreeDNav : MonoBehaviour
  9. {
  10. public Vector2[] targetPos;
  11. public Image s_image;
  12. public List<Button> btns;
  13. public List<RectTransform> layers;
  14. public GameObject content;
  15. public RectTransform znz;
  16. public GCJKLayer gCJK;
  17. public ObsPlayerPanel obsPlayerPanel;
  18. public static ThreeDNav instance;
  19. private void Awake()
  20. {
  21. instance = this;
  22. }
  23. private void Start()
  24. {
  25. CameraManager.SwitchCamera(0);
  26. InitButton();
  27. StaticLod.instance.OnFoucusStatic("TaoKou");
  28. InitPoint();
  29. }
  30. void InitButton()
  31. {
  32. btns = new List<Button>();
  33. Button[] bts = this.GetComponentsInChildren<Button>();
  34. for (int i = 0; i < bts.Length; i++)
  35. {
  36. btns.Add(bts[i]);
  37. }
  38. layers = new List<RectTransform>();
  39. for (int i = 0; i < content.transform.childCount; i++)
  40. {
  41. layers.Add(content.transform.GetChild(i).GetComponent<RectTransform>());
  42. }
  43. for (int i = 0; i < btns.Count; i++)
  44. {
  45. int index = i;
  46. btns[index].onClick.AddListener(() =>
  47. {
  48. for (int j = 0; j < layers.Count; j++)
  49. {
  50. layers[j].gameObject.SetActive(false);
  51. }
  52. for (int j = 0; j < btns.Count; j++)
  53. {
  54. btns[j].GetComponentInChildren<Text>().color = new Color32(137, 147, 173, 255);
  55. }
  56. obsPlayerPanel.gameObject.SetActive(false);
  57. btns[index].GetComponentInChildren<Text>().color = Color.white;
  58. Tweener tw = s_image.GetComponent<RectTransform>().DOLocalMoveX(targetPos[index].x, 0.3f);
  59. tw.SetEase(Ease.OutBack);
  60. if (index < layers.Count)
  61. {
  62. layers[index].gameObject.SetActive(true);
  63. }
  64. if (index == 4)
  65. {
  66. StaticLod.instance.OnFoucusStatic("Bird0");
  67. }
  68. else if (index == 1)
  69. {
  70. gCJK.OnTaoKouClick();
  71. }
  72. else
  73. {
  74. StaticLod.instance.OnFoucusStatic("TaoKou");
  75. }
  76. });
  77. }
  78. }
  79. public Item0 item0Prefab;
  80. public GameObject item0Parent;
  81. public Sprite[] hotPointSprite;
  82. void OnNewPointClick(HotPointData temp, Item0 item0)
  83. {
  84. CameraManager.SwitchCamera(0);
  85. StaticLod.instance.OnFoucusStatic(item0.staticImp);
  86. }
  87. int FindIndexByLayerUnitName(string name)
  88. {
  89. for (int i = 0; i < GlobalData.layerUnitDatas.Count; i++)
  90. {
  91. if (GlobalData.layerUnitDatas[i].name == name.Trim())
  92. {
  93. return i;
  94. }
  95. }
  96. return -1;
  97. }
  98. async void InitPoint()
  99. {
  100. await new WaitUntil(() =>
  101. {
  102. return GlobalData.hotPointDatas.Count > 0;
  103. });
  104. GameObject shaPan = GameObject.FindGameObjectWithTag("ShaPan");
  105. List<Item0> item0s = new List<Item0>();
  106. for (int i = 0; i < GlobalData.hotPointDatas.Count; i++)
  107. {
  108. //if()
  109. HotPointData temp = GlobalData.hotPointDatas[i];
  110. int tempI = i;
  111. if ((int)temp.type == 6 || (int)temp.type == 7 || (int)temp.type == 9)
  112. {
  113. int index = FindIndexByLayerUnitName(temp.name);
  114. Item0 item0 = Instantiate(item0Prefab, Vector3.zero, Quaternion.identity);
  115. item0.InitPoint(hotPointSprite[(int)(temp.type)], temp.namePri, temp.name, GlobalData.layerUnitDatas[index].special);
  116. item0s.Add(item0);
  117. item0.onPointClick = () =>
  118. {
  119. OnNewPointClick(temp, item0);
  120. };
  121. }
  122. }
  123. for (int i = 0; i < item0s.Count; i++)
  124. {
  125. if (item0s[i].mSpecial != "1")
  126. item0s[i].GetComponent<RectTransform>().SetParent(item0Parent.transform);
  127. }
  128. for (int i = 0; i < item0s.Count; i++)
  129. {
  130. if (item0s[i].mSpecial == "1")
  131. item0s[i].GetComponent<RectTransform>().SetParent(item0Parent.transform);
  132. }
  133. }
  134. public void ShowObsPanel(ObsData _data)
  135. {
  136. obsPlayerPanel.gameObject.SetActive(true);
  137. obsPlayerPanel.SetObsData(_data);
  138. obsPlayerPanel.SetTitle(_data.name);
  139. }
  140. private void Update()
  141. {
  142. znz.transform.rotation = Quaternion.Lerp(znz.transform.rotation, Quaternion.Euler(0, 0, CameraManager.instance.mainCamera.transform.localEulerAngles.y), Time.deltaTime * 4);
  143. }
  144. }