GCZLLayer.cs 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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 RawImage InfoFM;
  28. private GameObject DetailPanel;
  29. private Button DetailExitButton;
  30. private Text DetailTitleText;
  31. private LayerUnitData currentData;
  32. private void Awake()
  33. {
  34. InfoPanel = this.transform.Find("InfoPanel").gameObject;
  35. InfoTitleText = InfoPanel.transform.Find("Title").GetComponent<Text>();
  36. InfoClassText= InfoPanel.transform.Find("Class").GetComponent<Text>();
  37. InfoNoText= InfoPanel.transform.Find("No").GetComponent<Text>();
  38. InfoDayText= InfoPanel.transform.Find("Day").GetComponent<Text>();
  39. InfoFM = InfoPanel.transform.Find("fm").GetComponent<RawImage>();
  40. InfoExitButton = InfoPanel.transform.Find("CloseButton").GetComponent<Button>();
  41. InfoExitButton.onClick.AddListener(() =>
  42. {
  43. InfoPanel.SetActive(false);
  44. });
  45. Info_DetailButton = InfoPanel.transform.Find("MoreButton").GetComponent<Button>();
  46. Info_DetailButton.onClick.AddListener(() =>
  47. {
  48. DetailTitleText.text = currentData.name;
  49. ModelCameraCtrl._Instance.SetCameraActive(true);
  50. DetailPanel.SetActive(true);
  51. });
  52. DetailPanel = this.transform.Find("DetailPanel").gameObject;
  53. DetailTitleText = DetailPanel.transform.Find("Title").GetComponent<Text>();
  54. DetailExitButton = DetailPanel.transform.Find("CloseButton").GetComponent<Button>();
  55. DetailExitButton.onClick.AddListener(() =>
  56. {
  57. DetailPanel.SetActive(false);
  58. ModelCameraCtrl._Instance.SetCameraActive(false);
  59. });
  60. InfoPanel.SetActive(false);
  61. DetailPanel.SetActive(false);
  62. }
  63. // Start is called before the first frame update
  64. async void Start()
  65. {
  66. await InitData();
  67. StaticLod.instance.OnFoucusStatic(0);
  68. CameraManager.SwitchCamera(0);
  69. InitButton();
  70. InitInformation(0);
  71. }
  72. void InitButton() {
  73. for (int i = 0; i < zTLayer.layerDatas.Length; i++) {
  74. string name = zTLayer.layerDatas[i].layerName;
  75. int temp = i;
  76. GameObject obj = Instantiate(classPrefab);
  77. obj.transform.SetParent(classContent);
  78. obj.GetComponentInChildren<Text>().text = name;
  79. obj.transform.localScale = Vector3.one;
  80. if (i == 0)
  81. {
  82. obj.GetComponent<Image>().sprite = sprites[0];
  83. lastClassBtn = obj;
  84. }
  85. else
  86. {
  87. obj.GetComponent<Image>().sprite = sprites[1];
  88. }
  89. obj.GetComponent<Button>().onClick.AddListener(()=> {
  90. InitInformation(temp);
  91. lastClassBtn.GetComponent<Image>().sprite = sprites[1];
  92. obj.GetComponent<Image>().sprite = sprites[0];
  93. lastClassBtn = obj;
  94. });
  95. }
  96. }
  97. void InitInformation(int index) {
  98. if (currentClass == index) return;
  99. for (int i = informations.Count - 1; i >= 0; i--) {
  100. Destroy(informations[i]);
  101. }
  102. informations.Clear();
  103. currentClass = index;
  104. if (currentClass == 0)
  105. {
  106. for (int i = 0; i < GlobalData.layerUnitDatas.Count; i++)
  107. {
  108. if (GlobalData.layerUnitDatas[i].special)
  109. {
  110. GameObject obj = Instantiate(informationPrefab);
  111. string realName = GlobalData.layerUnitDatas[i].name;
  112. string priName = GlobalData.layerUnitDatas[i].name_pri;
  113. var objType = GlobalData.layerUnitDatas[i].type;
  114. string className = GlobalData.layerUnitDatas[i].GetTypeName();
  115. obj.transform.SetParent(informationContent);
  116. obj.transform.Find("Name").GetComponentInChildren<Text>().text = realName;
  117. obj.transform.Find("Class").GetComponentInChildren<Text>().text = className;
  118. //todo
  119. obj.transform.Find("No").GetComponentInChildren<Text>().text = "未知";
  120. obj.transform.Find("Day").GetComponentInChildren<Text>().text = "近期";
  121. obj.transform.Find("fm").GetComponent<RawImage>().texture =
  122. TextureLoadHelp._Instance.GetTempTexture(priName);
  123. obj.transform.localScale = Vector3.one;
  124. informations.Add(obj);
  125. int dataIndex = i;
  126. obj.GetComponent<Button>().onClick.AddListener(() =>
  127. {
  128. currentData = GlobalData.layerUnitDatas[dataIndex];
  129. StaticLod.instance.OnFoucusStatic(priName);
  130. if (objType == LayerUnitType.ZZ|| objType==LayerUnitType.BZ)
  131. {
  132. Info_DetailButton.gameObject.SetActive(true);
  133. }
  134. else
  135. {
  136. Info_DetailButton.gameObject.SetActive(false);
  137. }
  138. ShowInfoPanelData();
  139. });
  140. }
  141. }
  142. }
  143. else {
  144. for (int i = 0; i < GlobalData.layerUnitDatas.Count; i++)
  145. {
  146. if (GlobalData.layerUnitDatas[i].type == (LayerUnitType)currentClass)
  147. {
  148. GameObject obj = Instantiate(informationPrefab);
  149. string realName = GlobalData.layerUnitDatas[i].name;
  150. string priName = GlobalData.layerUnitDatas[i].name_pri;
  151. var objType = GlobalData.layerUnitDatas[i].type;
  152. string className = GlobalData.layerUnitDatas[i].GetTypeName();
  153. obj.transform.SetParent(informationContent);
  154. obj.transform.Find("Name").GetComponentInChildren<Text>().text = realName;
  155. obj.transform.Find("Class").GetComponentInChildren<Text>().text = className;
  156. //todo
  157. obj.transform.Find("No").GetComponentInChildren<Text>().text = "未知";
  158. obj.transform.Find("Day").GetComponentInChildren<Text>().text = "近期";
  159. obj.transform.Find("fm").GetComponent<RawImage>().texture =
  160. TextureLoadHelp._Instance.GetTempTexture(priName);
  161. obj.transform.localScale = Vector3.one;
  162. informations.Add(obj);
  163. int dataIndex = i;
  164. obj.GetComponent<Button>().onClick.AddListener(() =>
  165. {
  166. currentData = GlobalData.layerUnitDatas[dataIndex];
  167. StaticLod.instance.OnFoucusStatic(priName);
  168. if (objType == LayerUnitType.ZZ|| objType==LayerUnitType.BZ)
  169. {
  170. Info_DetailButton.gameObject.SetActive(true);
  171. }
  172. else
  173. {
  174. Info_DetailButton.gameObject.SetActive(false);
  175. }
  176. ShowInfoPanelData();
  177. });
  178. }
  179. }
  180. }
  181. }
  182. async Task InitData()
  183. {
  184. await new WaitUntil(() =>
  185. {
  186. return GlobalData.layerUnitDatas.Count > 0;
  187. });
  188. }
  189. public void ShowInfoPanelData()
  190. {
  191. InfoTitleText.text = currentData.name;
  192. InfoClassText.text = currentData.GetTypeName();
  193. InfoFM.texture = TextureLoadHelp._Instance.GetTempTexture(currentData.name_pri);
  194. //todo
  195. InfoNoText.text = "未知";
  196. InfoDayText.text = "近期";
  197. InfoPanel.SetActive(true);
  198. }
  199. }