BigScreenLayer.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683
  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. using System.Reflection;
  14. using XCharts.Runtime;
  15. [System.Serializable]
  16. public class FloodGate
  17. {
  18. public int GateNumber;
  19. public bool IsOpen;
  20. public float CurrentFlow;
  21. public float CurrentOpening;
  22. public int Status; // 1 for operational, 0 for faulty
  23. public string updateTime;
  24. }
  25. [System.Serializable]
  26. public class FloodGateLocationData
  27. {
  28. public float CurrentWaterLevel;
  29. public FloodGate[] FloodGates;
  30. }
  31. [System.Serializable]
  32. public class FloodGateStatusData
  33. {
  34. public FloodGateLocationData BuYuan;
  35. public FloodGateLocationData TaoKou;
  36. public bool success = false;
  37. public int BuYuanTotalGates => BuYuan.FloodGates.Length;
  38. public int BuYuanOperationalGates => CountOperationalGates(BuYuan.FloodGates);
  39. public int TaoKouTotalGates => TaoKou.FloodGates.Length;
  40. public int TaoKouOperationalGates => CountOperationalGates(TaoKou.FloodGates);
  41. private int CountOperationalGates(FloodGate[] gates)
  42. {
  43. int count = 0;
  44. foreach (var gate in gates)
  45. {
  46. if (gate.Status == 1) count++;
  47. }
  48. return count;
  49. }
  50. }
  51. [System.Serializable]
  52. public class LocationWeatherData
  53. {
  54. public float currentWaterLevel;
  55. public float rainfall;
  56. public float floodDischarge;
  57. public float temperature;
  58. public string weather;
  59. }
  60. [System.Serializable]
  61. public class StationInspection
  62. {
  63. public InspectionDaily daily;
  64. public InspectionDaily monthly;
  65. public InspectionDaily yearly;
  66. }
  67. [System.Serializable]
  68. public class InspectionDaily
  69. {
  70. public int operationStaffCount;
  71. public int inspectionTasksCount;
  72. public int inspectionKilometers;
  73. public int faultHazardCount;
  74. public int processedFaultCount;
  75. public int engineeringMaintenanceCount;
  76. }
  77. [System.Serializable]
  78. public class AlertData
  79. {
  80. public bool success = false;
  81. public Alerts alerts;
  82. }
  83. [System.Serializable]
  84. public class Alerts
  85. {
  86. public List<AlertDataEvent> warningEvents = new List<AlertDataEvent>();
  87. public List<AlertDataEvent> floodForecasts = new List<AlertDataEvent>();
  88. public List<AlertDataEvent> weatherForecasts = new List<AlertDataEvent>();
  89. public List<AlertDataEvent> threeLineWarnings = new List<AlertDataEvent>();
  90. }
  91. [System.Serializable]
  92. public class AlertDataEvent
  93. {
  94. public int id;
  95. public string title;
  96. public string location;
  97. public string time;
  98. }
  99. public class BigScreenLayer : MonoBehaviour
  100. {
  101. public VerticalLayoutGroup content;
  102. public RectTransform znz;
  103. public Button gkButton;
  104. public Button normalButton;
  105. public Button clearBtn;
  106. public Button exitBtn;
  107. public Button exitJJBtn;
  108. public Button ddysButton;
  109. public Button exit_ddysButton;
  110. public GameObject gk;
  111. public GameObject normal;
  112. public YZTLayer zTLayer;
  113. public RectTransform miniMap;
  114. public RectTransform rightContent;
  115. public RingChart floodRingChart;
  116. public Button floodButton;
  117. public Text[] floodTexts;
  118. public RectTransform popWindow;
  119. public GameObject floodDataPrefab;
  120. public Button[] floodListBtns;
  121. public GridLayoutGroup[] floodLists;
  122. public Button floodListExitBtn;
  123. public Text swValue1;
  124. public Text swValue2;
  125. public Text swValue3;
  126. public Text swValue4;
  127. public Text swValue5;
  128. public Dropdown swDrop0;
  129. public Text yunValue1;
  130. public Text yunValue2;
  131. public Text yunValue3;
  132. public Text yunValue4;
  133. public Text yunValue5;
  134. public Text yunValue6;
  135. public int currentYunIndex = 0;
  136. public Dropdown yunDrop0;
  137. public Dropdown yunDrop1;
  138. List<LayerBtn> layerBtns = new List<LayerBtn>();
  139. // Start is called before the first frame update
  140. public GameObject obsItemPrefab;
  141. private List<ObsItem> obsItemList = new List<ObsItem>();
  142. private Transform obsItemContent;
  143. public ObsPlayerPanel obsPlayerPanel;
  144. private InputField _obsSearchInputField;
  145. public GameObject WaterRangeCtrlPanel;
  146. public GameObject yjPrefab;
  147. public Button[] yjBtns;
  148. public GridLayoutGroup[] yjLayout;
  149. public Sprite[] sprites;
  150. async void Start()
  151. {
  152. CameraManager.SwitchCamera(0);
  153. StaticLod.instance.OnFoucusStatic(0);
  154. InitButton();
  155. obsPlayerPanel = this.transform.Find("ObsPlayerPanel").GetComponent<ObsPlayerPanel>();
  156. obsPlayerPanel.gameObject.SetActive(false);
  157. obsItemContent = this.transform.Find("BigSc/ShiPinJuZhen/ScrollView/Viewport/Content");
  158. _obsSearchInputField = this.transform.Find("BigSc/ShiPinJuZhen/InputField").GetComponent<InputField>();
  159. _obsSearchInputField.onValueChanged.AddListener(SearchObsItem);
  160. InitFloodGateData();
  161. InitHydrologicalData();
  162. InitLayerBtns();
  163. InitObsItems();
  164. InitInspectionStatistics();
  165. InitAlert();
  166. }
  167. void InitButton()
  168. {
  169. normalButton.onClick.AddListener(() =>
  170. {
  171. normal.gameObject.SetActive(true);
  172. gk.gameObject.SetActive(false);
  173. });
  174. gkButton.onClick.AddListener(() =>
  175. {
  176. gk.gameObject.SetActive(true);
  177. miniMap.gameObject.SetActive(true);
  178. rightContent.parent.gameObject.SetActive(false);
  179. normal.gameObject.SetActive(false);
  180. });
  181. clearBtn.onClick.AddListener(() =>
  182. {
  183. normal.gameObject.SetActive(false);
  184. gk.gameObject.SetActive(false);
  185. exitBtn.gameObject.SetActive(true);
  186. normalButton.gameObject.SetActive(false);
  187. gkButton.gameObject.SetActive(false);
  188. clearBtn.gameObject.SetActive(false);
  189. ddysButton.gameObject.SetActive(false);
  190. });
  191. exitBtn.onClick.AddListener(() =>
  192. {
  193. normal.gameObject.SetActive(true);
  194. gk.gameObject.SetActive(false);
  195. exitBtn.gameObject.SetActive(false);
  196. normalButton.gameObject.SetActive(true);
  197. gkButton.gameObject.SetActive(true);
  198. clearBtn.gameObject.SetActive(true);
  199. ddysButton.gameObject.SetActive(true);
  200. });
  201. exitJJBtn.onClick.AddListener(() =>
  202. {
  203. normal.gameObject.SetActive(true);
  204. gk.gameObject.SetActive(false);
  205. });
  206. ddysButton.onClick.AddListener(() =>
  207. {
  208. StaticLod.instance.OnFoucusStatic(-1);
  209. normal.gameObject.SetActive(false);
  210. gk.gameObject.SetActive(false);
  211. normalButton.gameObject.SetActive(false);
  212. gkButton.gameObject.SetActive(false);
  213. clearBtn.gameObject.SetActive(false);
  214. WaterRangeCtrlPanel.SetActive(true);
  215. });
  216. exit_ddysButton.onClick.AddListener(() =>
  217. {
  218. StaticLod.instance.OnFoucusStatic(0);
  219. WaterRangeCtrlPanel.SetActive(false);
  220. normal.gameObject.SetActive(true);
  221. gk.gameObject.SetActive(false);
  222. exitBtn.gameObject.SetActive(false);
  223. normalButton.gameObject.SetActive(true);
  224. gkButton.gameObject.SetActive(true);
  225. clearBtn.gameObject.SetActive(true);
  226. ddysButton.gameObject.SetActive(true);
  227. });
  228. // public Button ddysButton;
  229. // public Button exit_ddysButton;
  230. }
  231. private async Task InitAlert()
  232. {
  233. await new WaitUntil(() =>
  234. {
  235. return GlobalData.alertData.success;
  236. });
  237. for (int i = 0; i < yjLayout.Length; i++)
  238. {
  239. yjLayout[i].transform.parent.parent.parent.gameObject.SetActive(false);
  240. }
  241. yjLayout[0].transform.parent.parent.parent.gameObject.SetActive(true);
  242. for (int i = 0; i < GlobalData.alertData.alerts.warningEvents.Count; i++)
  243. {
  244. GameObject obj = Instantiate(yjPrefab);
  245. obj.transform.SetParent(yjLayout[0].transform);
  246. obj.transform.localScale = Vector3.one;
  247. obj.transform.GetChild(0).GetComponent<Text>().text = GlobalData.alertData.alerts.warningEvents[i].id.ToString();
  248. obj.transform.GetChild(1).GetComponent<Text>().text = GlobalData.alertData.alerts.warningEvents[i].title.ToString();
  249. obj.transform.GetChild(2).GetComponent<Text>().text = GlobalData.alertData.alerts.warningEvents[i].location.ToString();
  250. obj.transform.GetChild(3).GetComponent<Text>().text = GlobalData.alertData.alerts.warningEvents[i].time.ToString();
  251. }
  252. for (int i = 0; i < GlobalData.alertData.alerts.floodForecasts.Count; i++)
  253. {
  254. GameObject obj = Instantiate(yjPrefab);
  255. obj.transform.SetParent(yjLayout[1].transform);
  256. obj.transform.localScale = Vector3.one;
  257. obj.transform.GetChild(0).GetComponent<Text>().text = GlobalData.alertData.alerts.floodForecasts[i].id.ToString();
  258. obj.transform.GetChild(1).GetComponent<Text>().text = GlobalData.alertData.alerts.floodForecasts[i].title.ToString();
  259. obj.transform.GetChild(2).GetComponent<Text>().text = GlobalData.alertData.alerts.floodForecasts[i].location.ToString();
  260. obj.transform.GetChild(3).GetComponent<Text>().text = GlobalData.alertData.alerts.floodForecasts[i].time.ToString();
  261. }
  262. for (int i = 0; i < GlobalData.alertData.alerts.weatherForecasts.Count; i++)
  263. {
  264. GameObject obj = Instantiate(yjPrefab);
  265. obj.transform.SetParent(yjLayout[2].transform);
  266. obj.transform.localScale = Vector3.one;
  267. obj.transform.GetChild(0).GetComponent<Text>().text = GlobalData.alertData.alerts.weatherForecasts[i].id.ToString();
  268. obj.transform.GetChild(1).GetComponent<Text>().text = GlobalData.alertData.alerts.weatherForecasts[i].title.ToString();
  269. obj.transform.GetChild(2).GetComponent<Text>().text = GlobalData.alertData.alerts.weatherForecasts[i].location.ToString();
  270. obj.transform.GetChild(3).GetComponent<Text>().text = GlobalData.alertData.alerts.weatherForecasts[i].time.ToString();
  271. }
  272. for (int i = 0; i < GlobalData.alertData.alerts.threeLineWarnings.Count; i++)
  273. {
  274. GameObject obj = Instantiate(yjPrefab);
  275. obj.transform.SetParent(yjLayout[3].transform);
  276. obj.transform.localScale = Vector3.one;
  277. obj.transform.GetChild(0).GetComponent<Text>().text = GlobalData.alertData.alerts.threeLineWarnings[i].id.ToString();
  278. obj.transform.GetChild(1).GetComponent<Text>().text = GlobalData.alertData.alerts.threeLineWarnings[i].title.ToString();
  279. obj.transform.GetChild(2).GetComponent<Text>().text = GlobalData.alertData.alerts.threeLineWarnings[i].location.ToString();
  280. obj.transform.GetChild(3).GetComponent<Text>().text = GlobalData.alertData.alerts.threeLineWarnings[i].time.ToString();
  281. }
  282. for (int i = 0; i < yjBtns.Length; i++)
  283. {
  284. int temp = i;
  285. yjBtns[i].onClick.AddListener(() =>
  286. {
  287. for (int j = 0; j < yjBtns.Length; j++)
  288. {
  289. yjBtns[j].transform.GetChild(0).GetComponent<Text>().color = Color.gray;
  290. }
  291. yjBtns[temp].transform.GetChild(0).GetComponent<Text>().color = Color.white;
  292. for (int j = 0; j < yjLayout.Length; j++)
  293. {
  294. yjLayout[j].transform.parent.parent.parent.gameObject.SetActive(false);
  295. }
  296. yjLayout[temp].transform.parent.parent.parent.gameObject.SetActive(true);
  297. });
  298. }
  299. }
  300. private async Task InitHydrologicalData()
  301. {
  302. await new WaitUntil(() =>
  303. {
  304. return GlobalData.locationWeatherData.Count > 0;
  305. });
  306. ChangeLocationWeatherData(0);
  307. swDrop0.onValueChanged.AddListener((index) =>
  308. {
  309. ChangeLocationWeatherData(index);
  310. });
  311. }
  312. private void ChangeLocationWeatherData(int index)
  313. {
  314. swValue1.text = GlobalData.locationWeatherData[index].currentWaterLevel.ToString();
  315. swValue2.text = GlobalData.locationWeatherData[index].rainfall.ToString();
  316. swValue3.text = GlobalData.locationWeatherData[index].temperature.ToString();
  317. swValue4.text = GlobalData.locationWeatherData[index].weather.ToString();
  318. swValue5.text = GlobalData.locationWeatherData[index].floodDischarge.ToString();
  319. }
  320. private async Task InitFloodGateData()
  321. {
  322. await new WaitUntil(() =>
  323. {
  324. return GlobalData.floorGateData.success;
  325. });
  326. floodTexts[0].text = (GlobalData.floorGateData.BuYuanOperationalGates + GlobalData.floorGateData.TaoKouOperationalGates).ToString();
  327. floodTexts[1].text = (GlobalData.floorGateData.BuYuanTotalGates + GlobalData.floorGateData.TaoKouTotalGates - GlobalData.floorGateData.BuYuanOperationalGates - GlobalData.floorGateData.TaoKouOperationalGates).ToString();
  328. floodTexts[2].text = (GlobalData.floorGateData.BuYuanTotalGates + GlobalData.floorGateData.TaoKouTotalGates).ToString();
  329. floodButton.onClick.AddListener(() =>
  330. {
  331. popWindow.gameObject.SetActive(true);
  332. });
  333. floodListExitBtn.onClick.AddListener(() =>
  334. {
  335. popWindow.gameObject.SetActive(false);
  336. });
  337. floodListBtns[0].onClick.AddListener(() =>
  338. {
  339. floodListBtns[0].GetComponent<Image>().sprite = sprites[0];
  340. floodListBtns[1].GetComponent<Image>().sprite = sprites[1];
  341. floodLists[0].transform.parent.parent.parent.gameObject.SetActive(true);
  342. floodLists[1].transform.parent.parent.parent.gameObject.SetActive(false);
  343. });
  344. floodListBtns[1].onClick.AddListener(() =>
  345. {
  346. floodListBtns[0].GetComponent<Image>().sprite = sprites[1];
  347. floodListBtns[1].GetComponent<Image>().sprite = sprites[0];
  348. floodLists[0].transform.parent.parent.parent.gameObject.SetActive(false);
  349. floodLists[1].transform.parent.parent.parent.gameObject.SetActive(true);
  350. });
  351. for (int i = 0; i < GlobalData.floorGateData.BuYuan.FloodGates.Length; i++)
  352. {
  353. GameObject floodGateDataObj = Instantiate(floodDataPrefab);
  354. floodGateDataObj.transform.SetParent(floodLists[0].transform);
  355. floodGateDataObj.transform.localScale = Vector3.one;
  356. floodGateDataObj.transform.GetChild(1).GetComponent<Text>().text = (i + 1).ToString("00") + "号闸门";
  357. floodGateDataObj.transform.GetChild(7).GetComponent<Text>().text = GlobalData.floorGateData.BuYuan.FloodGates[i].IsOpen ? "开启" : "关闭";
  358. floodGateDataObj.transform.GetChild(8).GetComponent<Text>().text = GlobalData.floorGateData.BuYuan.FloodGates[i].CurrentFlow + "m³/s";
  359. floodGateDataObj.transform.GetChild(9).GetComponent<Text>().text = GlobalData.floorGateData.BuYuan.CurrentWaterLevel + "m";
  360. floodGateDataObj.transform.GetChild(10).GetComponent<Text>().text = GlobalData.floorGateData.BuYuan.FloodGates[i].CurrentOpening + "°";
  361. switch (GlobalData.floorGateData.BuYuan.FloodGates[i].Status)
  362. {
  363. case 0:
  364. floodGateDataObj.transform.GetChild(11).GetComponent<Text>().text = "故障";
  365. break;
  366. case 1:
  367. floodGateDataObj.transform.GetChild(11).GetComponent<Text>().text = "正常";
  368. break;
  369. }
  370. }
  371. for (int i = 0; i < GlobalData.floorGateData.TaoKou.FloodGates.Length; i++)
  372. {
  373. GameObject floodGateDataObj = Instantiate(floodDataPrefab);
  374. floodGateDataObj.transform.SetParent(floodLists[1].transform);
  375. floodGateDataObj.transform.localScale = Vector3.one;
  376. floodGateDataObj.transform.GetChild(1).GetComponent<Text>().text = (i + 1).ToString("00") + "号闸门";
  377. floodGateDataObj.transform.GetChild(7).GetComponent<Text>().text = GlobalData.floorGateData.TaoKou.FloodGates[i].IsOpen ? "开启" : "关闭";
  378. floodGateDataObj.transform.GetChild(8).GetComponent<Text>().text = GlobalData.floorGateData.TaoKou.FloodGates[i].CurrentFlow + "m³/s";
  379. floodGateDataObj.transform.GetChild(9).GetComponent<Text>().text = GlobalData.floorGateData.TaoKou.CurrentWaterLevel + "m";
  380. floodGateDataObj.transform.GetChild(10).GetComponent<Text>().text = GlobalData.floorGateData.TaoKou.FloodGates[i].CurrentOpening + "°";
  381. switch (GlobalData.floorGateData.TaoKou.FloodGates[i].Status)
  382. {
  383. case 0:
  384. floodGateDataObj.transform.GetChild(11).GetComponent<Text>().text = "故障";
  385. break;
  386. case 1:
  387. floodGateDataObj.transform.GetChild(11).GetComponent<Text>().text = "正常";
  388. break;
  389. }
  390. }
  391. List<double> doubles = new List<double>();
  392. doubles.Add(90);
  393. doubles.Add(100);
  394. floodRingChart.UpdateData(0, 0, doubles);
  395. }
  396. private async Task InitInspectionStatistics()
  397. {
  398. await new WaitUntil(() =>
  399. {
  400. return GlobalData.InspectionStat.Count > 0;
  401. });
  402. currentYunIndex = 0;
  403. yunValue1.text = GlobalData.InspectionStat[0].daily.operationStaffCount.ToString();
  404. yunValue2.text = GlobalData.InspectionStat[0].daily.inspectionTasksCount.ToString();
  405. yunValue3.text = GlobalData.InspectionStat[0].daily.inspectionKilometers.ToString();
  406. yunValue4.text = GlobalData.InspectionStat[0].daily.faultHazardCount.ToString();
  407. yunValue5.text = GlobalData.InspectionStat[0].daily.processedFaultCount.ToString();
  408. yunValue6.text = GlobalData.InspectionStat[0].daily.engineeringMaintenanceCount.ToString();
  409. yunDrop0.onValueChanged.AddListener((index) =>
  410. {
  411. currentYunIndex = index;
  412. SwitchStationStat(yunDrop1.value);
  413. });
  414. yunDrop1.onValueChanged.AddListener((index) =>
  415. {
  416. SwitchStationStat(index);
  417. });
  418. }
  419. void SwitchStationStat(int index)
  420. {
  421. switch (index)
  422. {
  423. case 0:
  424. yunValue1.text = GlobalData.InspectionStat[currentYunIndex].daily.operationStaffCount.ToString();
  425. yunValue2.text = GlobalData.InspectionStat[currentYunIndex].daily.inspectionTasksCount.ToString();
  426. yunValue3.text = GlobalData.InspectionStat[currentYunIndex].daily.inspectionKilometers.ToString();
  427. yunValue4.text = GlobalData.InspectionStat[currentYunIndex].daily.faultHazardCount.ToString();
  428. yunValue5.text = GlobalData.InspectionStat[currentYunIndex].daily.processedFaultCount.ToString();
  429. yunValue6.text = GlobalData.InspectionStat[currentYunIndex].daily.engineeringMaintenanceCount.ToString();
  430. break;
  431. case 1:
  432. yunValue1.text = GlobalData.InspectionStat[currentYunIndex].monthly.operationStaffCount.ToString();
  433. yunValue2.text = GlobalData.InspectionStat[currentYunIndex].monthly.inspectionTasksCount.ToString();
  434. yunValue3.text = GlobalData.InspectionStat[currentYunIndex].monthly.inspectionKilometers.ToString();
  435. yunValue4.text = GlobalData.InspectionStat[currentYunIndex].monthly.faultHazardCount.ToString();
  436. yunValue5.text = GlobalData.InspectionStat[currentYunIndex].monthly.processedFaultCount.ToString();
  437. yunValue6.text = GlobalData.InspectionStat[currentYunIndex].monthly.engineeringMaintenanceCount.ToString();
  438. break;
  439. case 2:
  440. yunValue1.text = GlobalData.InspectionStat[currentYunIndex].yearly.operationStaffCount.ToString();
  441. yunValue2.text = GlobalData.InspectionStat[currentYunIndex].yearly.inspectionTasksCount.ToString();
  442. yunValue3.text = GlobalData.InspectionStat[currentYunIndex].yearly.inspectionKilometers.ToString();
  443. yunValue4.text = GlobalData.InspectionStat[currentYunIndex].yearly.faultHazardCount.ToString();
  444. yunValue5.text = GlobalData.InspectionStat[currentYunIndex].yearly.processedFaultCount.ToString();
  445. yunValue6.text = GlobalData.InspectionStat[currentYunIndex].yearly.engineeringMaintenanceCount.ToString();
  446. break;
  447. }
  448. }
  449. private async Task InitLayerBtns()
  450. {
  451. await new WaitUntil(() =>
  452. {
  453. return GlobalData.layerUnitDatas.Count > 0;
  454. });
  455. layerBtns = new List<LayerBtn>();
  456. for (int i = 0; i < zTLayer.layerDatas.Length; i++)
  457. {
  458. LayerBtn layerBtn = Instantiate(zTLayer.layerBtnPrefab);
  459. layerBtn.SetUseful(false);
  460. int index = i;
  461. int num = 0;
  462. if (i == 0)
  463. {
  464. List<LayerUnitData> tempDatas = new List<LayerUnitData>(GlobalData.layerUnitDatas);
  465. for (int j = 0; j < tempDatas.Count; j++)
  466. {
  467. if (tempDatas[j].special == "1")
  468. {
  469. int tempJ = j;
  470. SecLayerBtn secLayerBtn = Instantiate(zTLayer.secLayerBtnPrefab);
  471. secLayerBtn.SetLayerBtnData(tempDatas[j].name);
  472. secLayerBtn.GetComponent<RectTransform>().SetParent(layerBtn.secContent.GetComponent<RectTransform>());
  473. secLayerBtn.btn.onClick.AddListener(() =>
  474. {
  475. StaticLod.instance.OnFoucusStatic(tempDatas[tempJ].namePri);
  476. miniMap.gameObject.SetActive(false);
  477. ChangeRightContent(tempJ);
  478. });
  479. num++;
  480. }
  481. }
  482. layerBtn.secContent.gameObject.SetActive(true);
  483. }
  484. else
  485. {
  486. List<LayerUnitData> tempDatas = new List<LayerUnitData>(GlobalData.layerUnitDatas);
  487. for (int j = 0; j < tempDatas.Count; j++)
  488. {
  489. Debug.Log(zTLayer.layerDatas.Length);
  490. Debug.Log(i);
  491. if ((int)tempDatas[j].type == zTLayer.layerDatas[i].layerID)
  492. {
  493. int tempJ = j;
  494. SecLayerBtn secLayerBtn = Instantiate(zTLayer.secLayerBtnPrefab);
  495. secLayerBtn.SetLayerBtnData(tempDatas[j].name);
  496. secLayerBtn.GetComponent<RectTransform>().SetParent(layerBtn.secContent.GetComponent<RectTransform>());
  497. secLayerBtn.btn.onClick.AddListener(() =>
  498. {
  499. StaticLod.instance.OnFoucusStatic(tempDatas[tempJ].namePri);
  500. miniMap.gameObject.SetActive(false);
  501. ChangeRightContent(tempJ);
  502. });
  503. num++;
  504. }
  505. }
  506. }
  507. layerBtn.btn.GetComponent<Button>().onClick.AddListener(() =>
  508. {
  509. for (int j = 0; j < layerBtns.Count; j++)
  510. {
  511. layerBtns[j].SetUseful(false);
  512. layerBtns[j].secContent.gameObject.SetActive(false);
  513. }
  514. layerBtns[index].SetUseful(true);
  515. layerBtns[index].secContent.gameObject.SetActive(true);
  516. });
  517. layerBtn.SetLayerBtnData(zTLayer.layerSprite[zTLayer.layerDatas[i].layerID], zTLayer.layerDatas[i].layerName, num.ToString());
  518. layerBtn.GetComponent<RectTransform>().SetParent(content.GetComponent<RectTransform>());
  519. layerBtn.transform.localScale = Vector3.one;
  520. layerBtns.Add(layerBtn);
  521. }
  522. content.GetComponent<VerticalLayoutGroup>().SetLayoutVertical();
  523. layerBtns[0].SetUseful(true);
  524. }
  525. void ChangeRightContent(int index)
  526. {
  527. rightContent.parent.gameObject.SetActive(true);
  528. for (int i = 0; i < rightContent.childCount; i++)
  529. {
  530. rightContent.GetChild(i).gameObject.SetActive(false);
  531. }
  532. rightContent.GetChild(index).gameObject.SetActive(true);
  533. }
  534. // Update is called once per frame
  535. void Update()
  536. {
  537. znz.transform.rotation = Quaternion.Lerp(znz.transform.rotation, Quaternion.Euler(0, 0, CameraManager.instance.mainCamera.transform.localEulerAngles.y), Time.deltaTime * 4);
  538. }
  539. public async Task InitObsItems()
  540. {
  541. await new WaitUntil(() =>
  542. {
  543. return GlobalData.obsDatas_by.Count > 0&& GlobalData.obsDatas_tk.Count>0;
  544. });
  545. for (int i = 0; i < obsItemList.Count; i++)
  546. {
  547. Destroy(obsItemList[i].gameObject);
  548. }
  549. obsItemList.Clear();
  550. var obsDatasBy = GlobalData.obsDatas_by;
  551. for (int i = 0; i < obsDatasBy.Count; i++)
  552. {
  553. var tempObj = Instantiate(obsItemPrefab, obsItemContent).GetComponent<ObsItem>();
  554. tempObj.SetData(obsDatasBy[i]);
  555. tempObj._button.onClick.AddListener(() =>
  556. {
  557. ShowObsPanel(tempObj._data);
  558. });
  559. obsItemList.Add(tempObj);
  560. }
  561. var obsDatasTk = GlobalData.obsDatas_tk;
  562. for (int i = 0; i < obsDatasTk.Count; i++)
  563. {
  564. var tempObj = Instantiate(obsItemPrefab, obsItemContent).GetComponent<ObsItem>();
  565. tempObj.SetData(obsDatasTk[i]);
  566. tempObj._button.onClick.AddListener(() =>
  567. {
  568. ShowObsPanel(tempObj._data);
  569. });
  570. obsItemList.Add(tempObj);
  571. }
  572. }
  573. public void SearchObsItem(string s_name)
  574. {
  575. if (s_name.Equals(""))
  576. {
  577. for (int i = 0; i < obsItemList.Count; i++)
  578. {
  579. obsItemList[i].gameObject.SetActive(true);
  580. }
  581. }
  582. else
  583. {
  584. for (int i = 0; i < obsItemList.Count; i++)
  585. {
  586. obsItemList[i].gameObject.SetActive(obsItemList[i]._data.name.Contains(s_name));
  587. }
  588. }
  589. }
  590. public void ShowObsPanel(ObsData _data)
  591. {
  592. obsPlayerPanel.gameObject.SetActive(true);
  593. obsPlayerPanel.SetObsData(_data);
  594. }
  595. }