BigScreenLayer.cs 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. using Newtonsoft.Json.Linq;
  2. using Newtonsoft.Json;
  3. using System;
  4. using System.Collections;
  5. using System.Collections.Generic;
  6. using UnityEngine;
  7. using UnityEngine.Networking;
  8. using UnityEngine.Serialization;
  9. using UnityEngine.UI;
  10. using System.Threading.Tasks;
  11. using UnityAsync;
  12. using WaitUntil = UnityAsync.WaitUntil;
  13. public class BigScreenLayer : MonoBehaviour
  14. {
  15. public VerticalLayoutGroup content;
  16. public RectTransform znz;
  17. public Button gkButton;
  18. public Button normalButton;
  19. public Button clearBtn;
  20. public Button exitBtn;
  21. public Button exitJJBtn;
  22. public Button ddysButton;
  23. public Button exit_ddysButton;
  24. public GameObject gk;
  25. public GameObject normal;
  26. public YZTLayer zTLayer;
  27. public RectTransform miniMap;
  28. public RectTransform rightContent;
  29. List<LayerBtn> layerBtns = new List<LayerBtn>();
  30. // Start is called before the first frame update
  31. public GameObject obsItemPrefab;
  32. private List<ObsItem> obsItemList = new List<ObsItem>();
  33. private Transform obsItemContent;
  34. public ObsPlayerPanel obsPlayerPanel;
  35. private InputField _obsSearchInputField;
  36. public GameObject WaterRangeCtrlPanel;
  37. async void Start()
  38. {
  39. CameraManager.SwitchCamera(0);
  40. StaticLod.instance.OnFoucusStatic(0);
  41. InitButton();
  42. obsPlayerPanel = this.transform.Find("ObsPlayerPanel").GetComponent<ObsPlayerPanel>();
  43. obsPlayerPanel.gameObject.SetActive(false);
  44. obsItemContent = this.transform.Find("BigSc/ShiPinJuZhen/ScrollView/Viewport/Content");
  45. _obsSearchInputField = this.transform.Find("BigSc/ShiPinJuZhen/InputField").GetComponent<InputField>();
  46. _obsSearchInputField.onValueChanged.AddListener(SearchObsItem);
  47. await InitData();
  48. InitLayerBtns();
  49. await InitObsData();
  50. InitObsItems();
  51. }
  52. void InitButton() {
  53. normalButton.onClick.AddListener(()=>
  54. {
  55. normal.gameObject.SetActive(true);
  56. gk.gameObject.SetActive(false);
  57. });
  58. gkButton.onClick.AddListener(() =>
  59. {
  60. gk.gameObject.SetActive(true);
  61. miniMap.gameObject.SetActive(true);
  62. rightContent.parent.gameObject.SetActive(false);
  63. normal.gameObject.SetActive(false);
  64. });
  65. clearBtn.onClick.AddListener(() =>
  66. {
  67. normal.gameObject.SetActive(false);
  68. gk.gameObject.SetActive(false);
  69. exitBtn.gameObject.SetActive(true);
  70. normalButton.gameObject.SetActive(false);
  71. gkButton.gameObject.SetActive(false);
  72. clearBtn.gameObject.SetActive(false);
  73. ddysButton.gameObject.SetActive(false);
  74. });
  75. exitBtn.onClick.AddListener(() =>
  76. {
  77. normal.gameObject.SetActive(true);
  78. gk.gameObject.SetActive(false);
  79. exitBtn.gameObject.SetActive(false);
  80. normalButton.gameObject.SetActive(true);
  81. gkButton.gameObject.SetActive(true);
  82. clearBtn.gameObject.SetActive(true);
  83. ddysButton.gameObject.SetActive(true);
  84. });
  85. exitJJBtn.onClick.AddListener(() =>
  86. {
  87. normal.gameObject.SetActive(true);
  88. gk.gameObject.SetActive(false);
  89. });
  90. ddysButton.onClick.AddListener(() =>
  91. {
  92. StaticLod.instance.OnFoucusStatic(-1);
  93. normal.gameObject.SetActive(false);
  94. gk.gameObject.SetActive(false);
  95. normalButton.gameObject.SetActive(false);
  96. gkButton.gameObject.SetActive(false);
  97. clearBtn.gameObject.SetActive(false);
  98. WaterRangeCtrlPanel.SetActive(true);
  99. });
  100. exit_ddysButton.onClick.AddListener(() =>
  101. {
  102. StaticLod.instance.OnFoucusStatic(0);
  103. WaterRangeCtrlPanel.SetActive(false);
  104. normal.gameObject.SetActive(true);
  105. gk.gameObject.SetActive(false);
  106. exitBtn.gameObject.SetActive(false);
  107. normalButton.gameObject.SetActive(true);
  108. gkButton.gameObject.SetActive(true);
  109. clearBtn.gameObject.SetActive(true);
  110. ddysButton.gameObject.SetActive(true);
  111. });
  112. // public Button ddysButton;
  113. // public Button exit_ddysButton;
  114. }
  115. async Task InitData()
  116. {
  117. await new WaitUntil(() => {
  118. return GlobalData.layerUnitDatas.Count > 0;
  119. });
  120. }
  121. async Task InitObsData() {
  122. await new WaitUntil(() => {
  123. return GlobalData.obsDatas.Count > 0;
  124. });
  125. }
  126. void InitLayerBtns()
  127. {
  128. layerBtns = new List<LayerBtn>();
  129. for (int i = 0; i < zTLayer.layerDatas.Length; i++)
  130. {
  131. LayerBtn layerBtn = Instantiate(zTLayer.layerBtnPrefab);
  132. layerBtn.SetUseful(false);
  133. int index = i;
  134. int num = 0;
  135. if (i == 0)
  136. {
  137. List<LayerUnitData> tempDatas = new List<LayerUnitData>(GlobalData.layerUnitDatas);
  138. for (int j = 0; j < tempDatas.Count; j++)
  139. {
  140. if (tempDatas[j].special == "1")
  141. {
  142. int tempJ = j;
  143. SecLayerBtn secLayerBtn = Instantiate(zTLayer.secLayerBtnPrefab);
  144. secLayerBtn.SetLayerBtnData(tempDatas[j].name);
  145. secLayerBtn.GetComponent<RectTransform>().SetParent(layerBtn.secContent.GetComponent<RectTransform>());
  146. secLayerBtn.btn.onClick.AddListener(() =>
  147. {
  148. StaticLod.instance.OnFoucusStatic(tempDatas[tempJ].namePri);
  149. miniMap.gameObject.SetActive(false);
  150. ChangeRightContent(tempJ);
  151. });
  152. num++;
  153. }
  154. }
  155. layerBtn.secContent.gameObject.SetActive(true);
  156. }
  157. else
  158. {
  159. List<LayerUnitData> tempDatas = new List<LayerUnitData>(GlobalData.layerUnitDatas);
  160. for (int j = 0; j < tempDatas.Count; j++)
  161. {
  162. Debug.Log(zTLayer.layerDatas.Length);
  163. Debug.Log(i);
  164. if ((int)tempDatas[j].type == zTLayer.layerDatas[i].layerID)
  165. {
  166. int tempJ = j;
  167. SecLayerBtn secLayerBtn = Instantiate(zTLayer.secLayerBtnPrefab);
  168. secLayerBtn.SetLayerBtnData(tempDatas[j].name);
  169. secLayerBtn.GetComponent<RectTransform>().SetParent(layerBtn.secContent.GetComponent<RectTransform>());
  170. secLayerBtn.btn.onClick.AddListener(() =>
  171. {
  172. StaticLod.instance.OnFoucusStatic(tempDatas[tempJ].namePri);
  173. miniMap.gameObject.SetActive(false);
  174. ChangeRightContent(tempJ);
  175. });
  176. num++;
  177. }
  178. }
  179. }
  180. layerBtn.btn.GetComponent<Button>().onClick.AddListener(() =>
  181. {
  182. for (int j = 0; j < layerBtns.Count; j++)
  183. {
  184. layerBtns[j].SetUseful(false);
  185. layerBtns[j].secContent.gameObject.SetActive(false);
  186. }
  187. layerBtns[index].SetUseful(true);
  188. layerBtns[index].secContent.gameObject.SetActive(true);
  189. });
  190. layerBtn.SetLayerBtnData(zTLayer.layerSprite[zTLayer.layerDatas[i].layerID], zTLayer.layerDatas[i].layerName, num.ToString());
  191. layerBtn.GetComponent<RectTransform>().SetParent(content.GetComponent<RectTransform>());
  192. layerBtn.transform.localScale = Vector3.one;
  193. layerBtns.Add(layerBtn);
  194. }
  195. content.GetComponent<VerticalLayoutGroup>().SetLayoutVertical();
  196. layerBtns[0].SetUseful(true);
  197. }
  198. void ChangeRightContent(int index)
  199. {
  200. rightContent.parent.gameObject.SetActive(true);
  201. for (int i = 0; i < rightContent.childCount; i++)
  202. {
  203. rightContent.GetChild(i).gameObject.SetActive(false);
  204. }
  205. rightContent.GetChild(index).gameObject.SetActive(true);
  206. }
  207. // Update is called once per frame
  208. void Update()
  209. {
  210. znz.transform.rotation = Quaternion.Lerp(znz.transform.rotation, Quaternion.Euler(0, 0, CameraManager.instance.mainCamera.transform.localEulerAngles.y), Time.deltaTime * 4);
  211. }
  212. public void InitObsItems()
  213. {
  214. for (int i = 0; i < obsItemList.Count; i++)
  215. {
  216. Destroy(obsItemList[i].gameObject);
  217. }
  218. obsItemList.Clear();
  219. var obsDatas = GlobalData.obsDatas;
  220. for (int i = 0; i < obsDatas.Count; i++)
  221. {
  222. var tempObj = Instantiate(obsItemPrefab, obsItemContent).GetComponent<ObsItem>();
  223. tempObj.SetData(obsDatas[i]);
  224. tempObj._button.onClick.AddListener(()=>
  225. {
  226. ShowObsPanel(tempObj._data);
  227. });
  228. obsItemList.Add(tempObj);
  229. }
  230. }
  231. public void SearchObsItem(string s_name)
  232. {
  233. if (s_name.Equals(""))
  234. {
  235. for (int i = 0; i < obsItemList.Count; i++)
  236. {
  237. obsItemList[i].gameObject.SetActive(true);
  238. }
  239. }
  240. else
  241. {
  242. for (int i = 0; i < obsItemList.Count; i++)
  243. {
  244. obsItemList[i].gameObject.SetActive(obsItemList[i]._data.name.Contains(s_name));
  245. }
  246. }
  247. }
  248. public void ShowObsPanel(ObsData _data)
  249. {
  250. obsPlayerPanel.gameObject.SetActive(true);
  251. obsPlayerPanel.SetObsData(_data);
  252. }
  253. }