GCZLLayer.cs 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using UnityAsync;
  6. using WaitUntil = UnityAsync.WaitUntil;
  7. using System.Threading.Tasks;
  8. using UnityEngine.UI;
  9. public class GCZLLayer : MonoBehaviour
  10. {
  11. public GameObject classPrefab;
  12. public GameObject informationPrefab;
  13. public RectTransform classContent;
  14. public RectTransform informationContent;
  15. public YZTLayer zTLayer;
  16. public Sprite[] sprites;
  17. private List<GameObject> informations = new List<GameObject>();
  18. private GameObject lastClassBtn;
  19. private int currentClass = -99;
  20. private GameObject InfoPanel;
  21. private Button InfoExitButton;
  22. private Button Info_DetailButton;
  23. private Text InfoTitleText;
  24. private Text InfoClassText;
  25. private Text InfoNoText;
  26. private Text InfoDayText;
  27. private GameObject DetailPanel;
  28. private Button DetailExitButton;
  29. private Text DetailTitleText;
  30. private LayerUnitData currentData;
  31. private void Awake()
  32. {
  33. InfoPanel = this.transform.Find("InfoPanel").gameObject;
  34. InfoTitleText = InfoPanel.transform.Find("Title").GetComponent<Text>();
  35. InfoClassText= InfoPanel.transform.Find("Class").GetComponent<Text>();
  36. InfoNoText= InfoPanel.transform.Find("No").GetComponent<Text>();
  37. InfoDayText= InfoPanel.transform.Find("Day").GetComponent<Text>();
  38. InfoExitButton = InfoPanel.transform.Find("CloseButton").GetComponent<Button>();
  39. InfoExitButton.onClick.AddListener(() =>
  40. {
  41. InfoPanel.SetActive(false);
  42. });
  43. Info_DetailButton = InfoPanel.transform.Find("MoreButton").GetComponent<Button>();
  44. Info_DetailButton.onClick.AddListener(() =>
  45. {
  46. DetailTitleText.text = currentData.name;
  47. DetailPanel.SetActive(true);
  48. });
  49. DetailPanel = this.transform.Find("DetailPanel").gameObject;
  50. DetailTitleText = DetailPanel.transform.Find("Title").GetComponent<Text>();
  51. DetailExitButton = DetailPanel.transform.Find("CloseButton").GetComponent<Button>();
  52. DetailExitButton.onClick.AddListener(() =>
  53. {
  54. DetailPanel.SetActive(false);
  55. });
  56. InfoPanel.SetActive(false);
  57. DetailPanel.SetActive(false);
  58. }
  59. // Start is called before the first frame update
  60. async void Start()
  61. {
  62. await InitData();
  63. StaticLod.instance.OnFoucusStatic(0);
  64. CameraManager.SwitchCamera(0);
  65. InitButton();
  66. InitInformation(0);
  67. }
  68. void InitButton() {
  69. for (int i = 0; i < zTLayer.layerDatas.Length; i++) {
  70. string name = zTLayer.layerDatas[i].layerName;
  71. int temp = i;
  72. GameObject obj = Instantiate(classPrefab);
  73. obj.transform.SetParent(classContent);
  74. obj.GetComponentInChildren<Text>().text = name;
  75. obj.transform.localScale = Vector3.one;
  76. if (i == 0)
  77. {
  78. obj.GetComponent<Image>().sprite = sprites[0];
  79. lastClassBtn = obj;
  80. }
  81. else
  82. {
  83. obj.GetComponent<Image>().sprite = sprites[1];
  84. }
  85. obj.GetComponent<Button>().onClick.AddListener(()=> {
  86. InitInformation(temp);
  87. lastClassBtn.GetComponent<Image>().sprite = sprites[1];
  88. obj.GetComponent<Image>().sprite = sprites[0];
  89. lastClassBtn = obj;
  90. });
  91. }
  92. }
  93. void InitInformation(int index) {
  94. if (currentClass == index) return;
  95. for (int i = informations.Count - 1; i >= 0; i--) {
  96. Destroy(informations[i]);
  97. }
  98. informations.Clear();
  99. currentClass = index;
  100. if (currentClass == 0)
  101. {
  102. for (int i = 0; i < GlobalData.layerUnitDatas.Count; i++)
  103. {
  104. if (GlobalData.layerUnitDatas[i].special)
  105. {
  106. GameObject obj = Instantiate(informationPrefab);
  107. string realName = GlobalData.layerUnitDatas[i].name;
  108. string priName = GlobalData.layerUnitDatas[i].name_pri;
  109. string className = GlobalData.layerUnitDatas[i].GetTypeName();
  110. obj.transform.SetParent(informationContent);
  111. obj.transform.Find("Name").GetComponentInChildren<Text>().text = realName;
  112. obj.transform.Find("Class").GetComponentInChildren<Text>().text = className;
  113. //todo
  114. obj.transform.Find("No").GetComponentInChildren<Text>().text = "未知";
  115. obj.transform.Find("Day").GetComponentInChildren<Text>().text = "近期";
  116. obj.transform.localScale = Vector3.one;
  117. informations.Add(obj);
  118. int dataIndex = i;
  119. obj.GetComponent<Button>().onClick.AddListener(() =>
  120. {
  121. currentData = GlobalData.layerUnitDatas[dataIndex];
  122. StaticLod.instance.OnFoucusStatic(priName);
  123. ShowInfoPanelData();
  124. });
  125. }
  126. }
  127. }
  128. else {
  129. for (int i = 0; i < GlobalData.layerUnitDatas.Count; i++)
  130. {
  131. if (GlobalData.layerUnitDatas[i].type == (LayerUnitType)currentClass)
  132. {
  133. GameObject obj = Instantiate(informationPrefab);
  134. string realName = GlobalData.layerUnitDatas[i].name;
  135. string priName = GlobalData.layerUnitDatas[i].name_pri;
  136. string className = GlobalData.layerUnitDatas[i].GetTypeName();
  137. obj.transform.SetParent(informationContent);
  138. obj.transform.Find("Name").GetComponentInChildren<Text>().text = realName;
  139. obj.transform.Find("Class").GetComponentInChildren<Text>().text = className;
  140. //todo
  141. obj.transform.Find("No").GetComponentInChildren<Text>().text = "未知";
  142. obj.transform.Find("Day").GetComponentInChildren<Text>().text = "近期";
  143. obj.transform.localScale = Vector3.one;
  144. informations.Add(obj);
  145. int dataIndex = i;
  146. obj.GetComponent<Button>().onClick.AddListener(() =>
  147. {
  148. currentData = GlobalData.layerUnitDatas[dataIndex];
  149. StaticLod.instance.OnFoucusStatic(priName);
  150. ShowInfoPanelData();
  151. });
  152. }
  153. }
  154. }
  155. }
  156. async Task InitData()
  157. {
  158. await new WaitUntil(() =>
  159. {
  160. return GlobalData.layerUnitDatas.Count > 0;
  161. });
  162. }
  163. public void ShowInfoPanelData()
  164. {
  165. InfoTitleText.text = currentData.name;
  166. InfoClassText.text = currentData.GetTypeName();
  167. //todo
  168. InfoNoText.text = "未知";
  169. InfoDayText.text = "近期";
  170. InfoPanel.SetActive(true);
  171. }
  172. }