YZTLayer.cs 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082
  1. using Newtonsoft.Json;
  2. using Newtonsoft.Json.Linq;
  3. using System;
  4. using System.Collections;
  5. using System.Collections.Generic;
  6. using System.Threading.Tasks;
  7. using UnityEngine;
  8. using UnityEngine.Networking;
  9. using UnityEngine.UI;
  10. using UnityAsync;
  11. using WaitUntil = UnityAsync.WaitUntil;
  12. using DG.Tweening;
  13. using Unity.VisualScripting;
  14. using System.Reflection;
  15. [System.Serializable]
  16. public class YZTLayerData
  17. {
  18. public string layerName;
  19. public int layerID;
  20. }
  21. public enum LayerUnitType
  22. {
  23. ZZ = 1,
  24. BZ,
  25. NC,
  26. QXZ,
  27. JK,
  28. QT
  29. }
  30. [System.Serializable]
  31. public class JKYJData {
  32. public int normal;
  33. public int total;
  34. public int fault;
  35. public List<JKYJChildData> items;
  36. }
  37. [System.Serializable]
  38. public class JKYJChildData
  39. {
  40. public string name;
  41. public string model;
  42. public string ipAddress;
  43. public string deviceId;
  44. public string channelId;
  45. public bool onlineStatus;
  46. }
  47. public class GCGKData
  48. {
  49. public string name;
  50. public string type;
  51. public int count;
  52. }
  53. [System.Serializable]
  54. public class LayerUnitData
  55. {
  56. public string special;
  57. public LayerUnitType type;
  58. public float longitude;
  59. public float latitude;
  60. public string name;
  61. public string namePri;
  62. public string text1;
  63. public string text2;
  64. public string GetTypeName()
  65. {
  66. string result = "";
  67. switch (type)
  68. {
  69. case LayerUnitType.ZZ:
  70. result = "闸站";
  71. break;
  72. case LayerUnitType.BZ:
  73. result = "泵站";
  74. break;
  75. case LayerUnitType.NC:
  76. result = "农场";
  77. break;
  78. case LayerUnitType.QXZ:
  79. result = "气象站";
  80. break;
  81. case LayerUnitType.JK:
  82. result = "监控";
  83. break;
  84. case LayerUnitType.QT:
  85. result = "其他";
  86. break;
  87. }
  88. return result;
  89. }
  90. }
  91. [System.Serializable]
  92. public class HotPointData
  93. {
  94. public LayerUnitType type;
  95. public float longitude;
  96. public float latitude;
  97. public string name;
  98. public string namePri;
  99. }
  100. [System.Serializable]
  101. public class SWStationRecordData
  102. {
  103. public string name;
  104. public string time;
  105. public float value;
  106. public int dir;
  107. public string stcd = "0";
  108. }
  109. public class YZTLayer : YZTRootLayer
  110. {
  111. public VerticalLayoutGroup content;
  112. public Sprite[] layerSprite;
  113. public Sprite[] hotPointSprite;
  114. public LayerBtn layerBtnPrefab;
  115. public SecLayerBtn secLayerBtnPrefab;
  116. public YZTLayerData[] layerDatas;
  117. public RectTransform leftContent;
  118. public RectTransform middleContent;
  119. public RectTransform rightContent;
  120. List<LayerBtn> layerBtns = new List<LayerBtn>();
  121. public RuntimePoint pointPrefab;
  122. public GameObject runtimePointObj;
  123. public RectTransform pointParent;
  124. List<RuntimePoint> runtimePointLib = new List<RuntimePoint>();
  125. public GameObject yZTMini;
  126. public GameObject yZT;
  127. public RectTransform infoRight;
  128. public Button returnBtn;
  129. private float clickInterval;
  130. private Vector3 startClickPosition;
  131. public Button[] leftButtons;
  132. public Button layerButton;
  133. public int currentActiveLeft = 0;
  134. public RectTransform layerInfo;
  135. public Button layerInfoExitBtn;
  136. public Button[] baseLayerInfoBtns;
  137. public Button[] layerInfoBtns;
  138. public List<int> cancelLayer = new List<int>();
  139. public Sprite[] sprites;
  140. public Text rainText;
  141. public Text[] rainTextNum;
  142. public GameObject thingPrefab;
  143. public RectTransform thingParent;
  144. public List<SWStationRecordData> rescordSWStationData = new List<SWStationRecordData>();
  145. public List<GameObject> thing3s = new List<GameObject>();
  146. public Button clearBtn;
  147. public RectTransform regionParent;
  148. public RectTransform[] riverLayerInfo;
  149. public RectTransform[] lakeLayerInfo;
  150. public GameObject regionObjParent;
  151. public GameObject regionObjParent2;
  152. public GameObject[] regionLayerObj;
  153. public GameObject[] riverLayerObj;
  154. public GameObject[] lakeLayerObj;
  155. public List<GameObject> region2LayerObj = new List<GameObject>();
  156. // Start is called before the first frame update
  157. public WaterTrendPanel _waterTrendPanel;
  158. public Item0 item0Prefab;
  159. public GameObject item0Parent;
  160. public Text normalCount;
  161. public Text badCount;
  162. public Text stopCount;
  163. public Text allCount;
  164. public Thing0 thing0Prefab;
  165. public RectTransform thing0Content;
  166. public Text totalJKNum;
  167. public Text normalJKNum;
  168. public Text errorJKNum;
  169. public Text currentSWText;
  170. public Text avgSWText;
  171. public Text sfSWText;
  172. public Text jjSWText;
  173. public Text bzSWText;
  174. async void Awake()
  175. {
  176. viewMode = ViewMode.miniMap;
  177. _waterTrendPanel = this.transform.Find("WaterTrendPanel").GetComponent<WaterTrendPanel>();
  178. _waterTrendPanel.Init();
  179. await InitData();
  180. Init();
  181. InitLeftBtn();
  182. InitLayerInfo();
  183. InitLayerBtns();
  184. InitReturnBtn();
  185. InitGCGKData();
  186. InitJKYJData();
  187. InitSWYJData();
  188. InitRainInfo();
  189. InitSWHeightInfo();
  190. await InitPointData();
  191. InitPoint();
  192. }
  193. async void InitGCGKData() {
  194. await new WaitUntil(() =>
  195. {
  196. return GlobalData.gcgkContents.Count > 2;
  197. });
  198. normalCount.text = GlobalData.gcgkContents[0].count.ToString() + "个";
  199. badCount.text = GlobalData.gcgkContents[1].count.ToString() + "个";
  200. stopCount.text = GlobalData.gcgkContents[2].count.ToString() + "个";
  201. allCount.text = (GlobalData.gcgkContents[0].count + GlobalData.gcgkContents[1].count + GlobalData.gcgkContents[2].count).ToString() + "个";
  202. }
  203. async void InitJKYJData()
  204. {
  205. // Debug.Log("111");
  206. await new WaitUntil(() =>
  207. {
  208. return GlobalData.byJKYJContents.total > 0 && GlobalData.tkJKYJContents.total > 0;
  209. });
  210. //Debug.Log("222");
  211. for (int i = 0; i < GlobalData.byJKYJContents.items.Count; i++) {
  212. Thing0 thing0 = Instantiate(thing0Prefab);
  213. thing0.transform.SetParent(thing0Content);
  214. thing0.transform.localPosition = Vector3.zero;
  215. thing0.transform.localScale = Vector3.one;
  216. thing0.SetData(i.ToString(), GlobalData.byJKYJContents.items[i].name, "补元", "开启", GlobalData.byJKYJContents.items[i].onlineStatus?"正常":"故障");
  217. }
  218. //Debug.Log("333");
  219. for (int i = 0; i < GlobalData.tkJKYJContents.items.Count; i++)
  220. {
  221. Thing0 thing0 = Instantiate(thing0Prefab);
  222. thing0.transform.SetParent(thing0Content);
  223. thing0.transform.localPosition = Vector3.zero;
  224. thing0.transform.localScale = Vector3.one;
  225. thing0.SetData((i + GlobalData.byJKYJContents.total).ToString(), GlobalData.tkJKYJContents.items[i].name, "套口", "开启", GlobalData.tkJKYJContents.items[i].onlineStatus ? "正常" : "故障");
  226. }
  227. // Debug.Log("444");
  228. totalJKNum.text = (GlobalData.byJKYJContents.total + GlobalData.tkJKYJContents.total).ToString();
  229. normalJKNum.text = (GlobalData.byJKYJContents.normal + GlobalData.tkJKYJContents.normal).ToString();
  230. errorJKNum.text = (GlobalData.byJKYJContents.fault + GlobalData.tkJKYJContents.fault).ToString();
  231. }
  232. async void InitSWYJData()
  233. {
  234. //Debug.Log("555");
  235. await new WaitUntil(() =>
  236. {
  237. return GlobalData.TaoKouShuiWeiDataList.Count > 1;
  238. });
  239. //Debug.Log("666");
  240. float value1 = GlobalData.TaoKouShuiWeiDataList[0].value;
  241. float value2 = GlobalData.TaoKouShuiWeiDataList[1].value;
  242. if (value1 > 1000)
  243. {
  244. value1 = value1 / 100.0f;
  245. }
  246. if (value2 > 1000)
  247. {
  248. value2 = value2 / 100.0f;
  249. }
  250. //Debug.Log("777");
  251. avgSWText.text = $"{((value1 + value2) / 2).ToString("0.00")}";
  252. sfSWText.text = $"{GlobalData.threeLevelShuiWeiDatas[1].floodProtectionLevel}";
  253. jjSWText.text = $"{GlobalData.threeLevelShuiWeiDatas[1].warningLevel}";
  254. bzSWText.text = $"{GlobalData.threeLevelShuiWeiDatas[1].guaranteeLevel}";
  255. currentSWText.text = value1.ToString("0.00");
  256. }
  257. void InitLeftBtn()
  258. {
  259. for (int i = 0; i < leftButtons.Length; i++)
  260. {
  261. int temp = i;
  262. leftButtons[i].onClick.AddListener(() =>
  263. {
  264. LeftBtnClick(temp);
  265. });
  266. }
  267. LeftBtnClick(0);
  268. clearBtn.onClick.AddListener(() =>
  269. {
  270. if (clearBtn.GetComponent<Image>().sprite == sprites[0])
  271. {
  272. for (int i = 0; i < leftButtons.Length; i++)
  273. leftButtons[i].gameObject.SetActive(false);
  274. clearBtn.GetComponent<Image>().sprite = sprites[1];
  275. DOTween.To(() => leftContent.GetComponent<RectTransform>().anchoredPosition, x => leftContent.GetComponent<RectTransform>().anchoredPosition = x, new Vector2(-219.74f, 0), 0.3f);
  276. DOTween.To(() => leftContent.GetComponent<CanvasGroup>().alpha, x => leftContent.GetComponent<CanvasGroup>().alpha = x, 0, 0.3f);
  277. pointParent.gameObject.SetActive(true);
  278. DOTween.To(() => middleContent.GetComponent<RectTransform>().anchoredPosition, x => middleContent.GetComponent<RectTransform>().anchoredPosition = x, new Vector2(400f, 540), 0.3f);
  279. DOTween.To(() => rightContent.GetComponent<RectTransform>().anchoredPosition, x => rightContent.GetComponent<RectTransform>().anchoredPosition = x, new Vector2(220.6f, 419.8932f), 0.3f);
  280. DOTween.To(() => rightContent.GetComponent<CanvasGroup>().alpha, x => rightContent.GetComponent<CanvasGroup>().alpha = x, 0, 0.3f);
  281. clearBtn.GetComponent<RectTransform>().DOLocalMoveX(-827f, 0.3f);
  282. }
  283. else
  284. {
  285. for (int i = 0; i < leftButtons.Length; i++)
  286. leftButtons[i].gameObject.SetActive(true);
  287. clearBtn.GetComponent<Image>().sprite = sprites[0];
  288. DOTween.To(() => leftContent.GetComponent<RectTransform>().anchoredPosition, x => leftContent.GetComponent<RectTransform>().anchoredPosition = x, new Vector2(219.74f, 0), 0.3f);
  289. DOTween.To(() => leftContent.GetComponent<CanvasGroup>().alpha, x => leftContent.GetComponent<CanvasGroup>().alpha = x, 1, 0.3f);
  290. pointParent.gameObject.SetActive(true);
  291. DOTween.To(() => middleContent.GetComponent<RectTransform>().anchoredPosition, x => middleContent.GetComponent<RectTransform>().anchoredPosition = x, new Vector2(0f, 540), 0.3f);
  292. DOTween.To(() => rightContent.GetComponent<RectTransform>().anchoredPosition, x => rightContent.GetComponent<RectTransform>().anchoredPosition = x, new Vector2(-220.6f, 419.8932f), 0.3f);
  293. DOTween.To(() => rightContent.GetComponent<CanvasGroup>().alpha, x => rightContent.GetComponent<CanvasGroup>().alpha = x, 1, 0.3f);
  294. clearBtn.GetComponent<RectTransform>().DOLocalMoveX(-457f, 0.3f);
  295. }
  296. });
  297. }
  298. async void InitSWHeightInfo()
  299. {
  300. await new WaitUntil(() =>
  301. {
  302. return GlobalData.swDatas.Count > 0;
  303. });
  304. if (rescordSWStationData.Count < 1)
  305. {
  306. for (int i = 0; i < GlobalData.swDatas.Count; i++)
  307. {
  308. SWStationRecordData sWStationRecordData = new SWStationRecordData();
  309. sWStationRecordData.dir = 0;
  310. sWStationRecordData.name = GlobalData.swDatas[i].STNM;
  311. sWStationRecordData.value = (GlobalData.swDatas[i].upz > GlobalData.swDatas[i].dwz) ? GlobalData.swDatas[i].upz : GlobalData.swDatas[i].dwz;
  312. sWStationRecordData.time = DateTime.Now.ToString("MM/dd HH:mm");
  313. sWStationRecordData.stcd = GlobalData.swDatas[i].STCD;
  314. rescordSWStationData.Add(sWStationRecordData);
  315. }
  316. for (int i = 0; i < rescordSWStationData.Count; i++)
  317. {
  318. GameObject obj = Instantiate(thingPrefab);
  319. obj.GetComponent<RectTransform>().SetParent(thingParent);
  320. obj.transform.localScale = Vector3.one;
  321. obj.transform.GetChild(0).GetComponent<Text>().text = (i + 1).ToString();
  322. string rescordSW_name = rescordSWStationData[i].name.ToString(); ;
  323. obj.transform.GetChild(1).GetComponent<Text>().text = rescordSW_name;
  324. obj.transform.GetChild(2).GetComponent<Text>().text = rescordSWStationData[i].time.ToString();
  325. obj.transform.GetChild(3).GetComponent<Text>().text = rescordSWStationData[i].value.ToString();
  326. string rescordSW_stcd = rescordSWStationData[i].stcd;
  327. obj.transform.GetComponent<Button>().onClick.AddListener(() =>
  328. {
  329. _waterTrendPanel.Show(rescordSW_stcd, rescordSW_name);
  330. });
  331. if (rescordSWStationData[i].dir == 0)
  332. {
  333. obj.transform.GetChild(4).localEulerAngles = new Vector3(0, 0, 0);
  334. }
  335. else if (rescordSWStationData[i].dir == 1)
  336. {
  337. obj.transform.GetChild(4).localEulerAngles = new Vector3(0, 0, 90);
  338. }
  339. else
  340. {
  341. obj.transform.GetChild(4).localEulerAngles = new Vector3(0, 0, -90);
  342. }
  343. thing3s.Add(obj);
  344. }
  345. }
  346. else
  347. {
  348. for (int i = 0; i < GlobalData.swDatas.Count; i++)
  349. {
  350. rescordSWStationData[i].name = GlobalData.swDatas[i].STNM;
  351. float lastValue = rescordSWStationData[i].value;
  352. rescordSWStationData[i].value = (GlobalData.swDatas[i].upz > GlobalData.swDatas[i].dwz) ? GlobalData.swDatas[i].upz : GlobalData.swDatas[i].dwz;
  353. rescordSWStationData[i].time = DateTime.Now.ToString("MM/dd HH:mm");
  354. if (rescordSWStationData[i].value > lastValue)
  355. {
  356. rescordSWStationData[i].dir = 1;
  357. }
  358. else if (rescordSWStationData[i].value > lastValue)
  359. {
  360. rescordSWStationData[i].dir = 0;
  361. }
  362. else
  363. {
  364. rescordSWStationData[i].dir = -1;
  365. }
  366. }
  367. for (int i = 0; i < rescordSWStationData.Count; i++)
  368. {
  369. thing3s[i].transform.GetChild(0).GetComponent<Text>().text = (i + 1).ToString();
  370. thing3s[i].transform.GetChild(1).GetComponent<Text>().text = rescordSWStationData[i].name.ToString();
  371. thing3s[i].transform.GetChild(2).GetComponent<Text>().text = rescordSWStationData[i].time.ToString();
  372. thing3s[i].transform.GetChild(3).GetComponent<Text>().text = rescordSWStationData[i].value.ToString();
  373. if (rescordSWStationData[i].dir == 0)
  374. {
  375. thing3s[i].transform.GetChild(4).localEulerAngles = new Vector3(0, 0, 0);
  376. }
  377. else if (rescordSWStationData[i].dir == 1)
  378. {
  379. thing3s[i].transform.GetChild(4).localEulerAngles = new Vector3(0, 0, 90);
  380. }
  381. else
  382. {
  383. thing3s[i].transform.GetChild(4).localEulerAngles = new Vector3(0, 0, -90);
  384. }
  385. }
  386. }
  387. }
  388. async void InitRainInfo()
  389. {
  390. await new WaitUntil(() =>
  391. {
  392. return GlobalData.qXZDatas.Count > 0;
  393. });
  394. int qxzCount = GlobalData.qXZDatas.Count;
  395. string maxName = "";
  396. float maxValue = -99f;
  397. int value010 = 0;
  398. int value1025 = 0;
  399. int value2550 = 0;
  400. int value50100 = 0;
  401. int value100200 = 0;
  402. int value200 = 0;
  403. for (int i = 0; i < qxzCount; i++)
  404. {
  405. float value = GlobalData.qXZDatas[i].dropSum6;
  406. if (value > maxValue)
  407. {
  408. maxValue = value;
  409. maxName = GlobalData.qXZDatas[i].STNM;
  410. }
  411. if (value >= 0 && value < 10)
  412. {
  413. value010++;
  414. }
  415. else if (value >= 10 && value < 25)
  416. {
  417. value1025++;
  418. }
  419. else if (value >= 25 && value < 50)
  420. {
  421. value2550++;
  422. }
  423. else if (value >= 50 && value < 100)
  424. {
  425. value50100++;
  426. }
  427. else if (value >= 100 && value < 200)
  428. {
  429. value100200++;
  430. }
  431. else
  432. {
  433. value200++;
  434. }
  435. }
  436. rainText.text = $"数据时间:17日12时至18日12时(过去24小时)\r\n蓄洪区共有{qxzCount}个雨量站,其中几个雨量站监测有降雨最大降雨测站为{maxName}站点,降雨量{maxValue}mm.";
  437. rainTextNum[0].text = value010.ToString();
  438. rainTextNum[1].text = value1025.ToString();
  439. rainTextNum[2].text = value2550.ToString();
  440. rainTextNum[3].text = value50100.ToString();
  441. rainTextNum[4].text = value100200.ToString();
  442. rainTextNum[5].text = value200.ToString();
  443. }
  444. void InitLayerInfo()
  445. {
  446. //layerInfoBtns = layerInfo.GetComponentsInChildren<Button>();
  447. for (int i = 0; i < layerInfoBtns.Length; i++)
  448. {
  449. int temp = i;
  450. layerInfoBtns[i].onClick.AddListener(() =>
  451. {
  452. RunTimeLayerClick(temp);
  453. });
  454. }
  455. layerButton.onClick.AddListener(() =>
  456. {
  457. layerInfo.gameObject.SetActive(true);
  458. });
  459. layerInfoExitBtn.onClick.AddListener(() =>
  460. {
  461. layerInfo.gameObject.SetActive(false);
  462. });
  463. baseLayerInfoBtns[0].onClick.AddListener(() =>
  464. {
  465. bool active = baseLayerInfoBtns[0].GetComponent<CanvasGroup>().alpha > 0.5f;
  466. BaseLayer0BtnOnClick(!active);
  467. });
  468. baseLayerInfoBtns[0].GetComponent<CanvasGroup>().alpha = 0.5f;
  469. baseLayerInfoBtns[1].onClick.AddListener(() =>
  470. {
  471. bool active = baseLayerInfoBtns[1].GetComponent<CanvasGroup>().alpha > 0.5f;
  472. baseLayerInfoBtns[1].GetComponent<CanvasGroup>().alpha = active ? 0.5f : 1.0f;
  473. bool newActive = !active;
  474. for (int i = 0; i < riverLayerObj.Length; i++)
  475. {
  476. riverLayerObj[i].gameObject.SetActive(newActive);
  477. riverLayerInfo[i].gameObject.SetActive(newActive);
  478. }
  479. });
  480. baseLayerInfoBtns[1].GetComponent<CanvasGroup>().alpha = 0.5f;
  481. baseLayerInfoBtns[2].onClick.AddListener(() =>
  482. {
  483. bool active = baseLayerInfoBtns[2].GetComponent<CanvasGroup>().alpha > 0.5f;
  484. BaseLayer2BtnOnClick(!active);
  485. });
  486. baseLayerInfoBtns[2].GetComponent<CanvasGroup>().alpha = 0.5f;
  487. for (int i = 0; i < regionObjParent2.transform.childCount; i++)
  488. {
  489. region2LayerObj.Add(regionObjParent2.transform.GetChild(i).gameObject);
  490. }
  491. baseLayerInfoBtns[3].onClick.AddListener(() =>
  492. {
  493. bool active = baseLayerInfoBtns[3].GetComponent<CanvasGroup>().alpha > 0.5f;
  494. BaseLayer3BtnOnClick(!active);
  495. });
  496. baseLayerInfoBtns[3].GetComponent<CanvasGroup>().alpha = 0.5f;
  497. }
  498. void BaseLayer0BtnOnClick(bool newActive)
  499. {
  500. baseLayerInfoBtns[0].GetComponent<CanvasGroup>().alpha = newActive ? 1f : 0.5f;
  501. if (newActive)
  502. {
  503. BaseLayer2BtnOnClick(false);
  504. BaseLayer3BtnOnClick(false);
  505. }
  506. for (int i = 0; i < regionLayerObj.Length; i++)
  507. {
  508. regionLayerObj[i].gameObject.SetActive(newActive);
  509. }
  510. }
  511. void BaseLayer2BtnOnClick(bool newActive)
  512. {
  513. if (newActive)
  514. {
  515. BaseLayer0BtnOnClick(false);
  516. BaseLayer3BtnOnClick(false);
  517. }
  518. baseLayerInfoBtns[2].GetComponent<CanvasGroup>().alpha = newActive ? 1f : 0.5f;
  519. for (int i = 0; i < lakeLayerObj.Length; i++)
  520. {
  521. lakeLayerObj[i].gameObject.SetActive(newActive);
  522. lakeLayerInfo[i].gameObject.SetActive(newActive);
  523. }
  524. }
  525. void BaseLayer3BtnOnClick(bool newActive)
  526. {
  527. if (newActive)
  528. {
  529. BaseLayer0BtnOnClick(false);
  530. BaseLayer2BtnOnClick(false);
  531. }
  532. baseLayerInfoBtns[3].GetComponent<CanvasGroup>().alpha = newActive ? 1f : 0.5f;
  533. for (int i = 0; i < region2LayerObj.Count; i++)
  534. {
  535. region2LayerObj[i].gameObject.SetActive(newActive);
  536. }
  537. }
  538. void RunTimeLayerClick(int temp)
  539. {
  540. bool active = layerInfoBtns[temp].GetComponent<CanvasGroup>().alpha > 0.5f;
  541. layerInfoBtns[temp].GetComponent<CanvasGroup>().alpha = active ? 0.5f : 1.0f;
  542. bool newActive = !active;
  543. ChangeRuntimeLayer(temp, newActive);
  544. }
  545. void LeftBtnClick(int index, bool record = true)
  546. {
  547. if (record)
  548. currentActiveLeft = index;
  549. for (int i = 0; i < leftButtons.Length; i++)
  550. {
  551. leftButtons[i].GetComponent<Image>().sprite = sprites[1];
  552. }
  553. leftButtons[index].GetComponent<Image>().sprite = sprites[0];
  554. for (int i = 0; i < leftContent.childCount; i++)
  555. {
  556. leftContent.transform.GetChild(i).gameObject.SetActive(false);
  557. }
  558. leftContent.transform.GetChild(index).gameObject.SetActive(true);
  559. if (index == 1)
  560. {
  561. InitSWHeightInfo();
  562. }
  563. }
  564. void InitLayerBtns()
  565. {
  566. layerBtns = new List<LayerBtn>();
  567. for (int i = 0; i < layerDatas.Length; i++)
  568. {
  569. LayerBtn layerBtn = Instantiate(layerBtnPrefab);
  570. layerBtn.SetUseful(false);
  571. int index = i;
  572. int num = 0;
  573. if (i == 0)
  574. {
  575. List<LayerUnitData> tempDatas = new List<LayerUnitData>(GlobalData.layerUnitDatas);
  576. for (int j = 0; j < tempDatas.Count; j++)
  577. {
  578. if (tempDatas[j].special == "1")
  579. {
  580. int tempJ = j;
  581. SecLayerBtn secLayerBtn = Instantiate(secLayerBtnPrefab);
  582. secLayerBtn.SetLayerBtnData(tempDatas[j].name);
  583. secLayerBtn.GetComponent<RectTransform>().SetParent(layerBtn.secContent.GetComponent<RectTransform>());
  584. secLayerBtn.btn.onClick.AddListener(() =>
  585. {
  586. CameraManager.SwitchCamera(0);
  587. viewMode = ViewMode.normal;
  588. StaticLod.instance.OnFoucusStatic(tempDatas[tempJ].namePri);
  589. yZT.gameObject.SetActive(true);
  590. ChangeRightContent(tempJ);
  591. pointParent.gameObject.SetActive(false);
  592. clearBtn.gameObject.SetActive(false);
  593. middleContent.gameObject.SetActive(false);
  594. rightContent.gameObject.SetActive(false);
  595. LeftBtnClick(1, false);
  596. });
  597. num++;
  598. }
  599. }
  600. layerBtn.secContent.gameObject.SetActive(true);
  601. }
  602. else
  603. {
  604. List<LayerUnitData> tempDatas = new List<LayerUnitData>(GlobalData.layerUnitDatas);
  605. for (int j = 0; j < tempDatas.Count; j++)
  606. {
  607. if ((int)tempDatas[j].type == layerDatas[i].layerID)
  608. {
  609. int tempJ = j;
  610. SecLayerBtn secLayerBtn = Instantiate(secLayerBtnPrefab);
  611. secLayerBtn.SetLayerBtnData(tempDatas[j].name);
  612. secLayerBtn.GetComponent<RectTransform>().SetParent(layerBtn.secContent.GetComponent<RectTransform>());
  613. secLayerBtn.btn.onClick.AddListener(() =>
  614. {
  615. CameraManager.SwitchCamera(0);
  616. viewMode = ViewMode.normal;
  617. StaticLod.instance.OnFoucusStatic(tempDatas[tempJ].namePri);
  618. yZT.gameObject.SetActive(true);
  619. ChangeRightContent(tempJ);
  620. pointParent.gameObject.SetActive(false);
  621. clearBtn.gameObject.SetActive(false);
  622. middleContent.gameObject.SetActive(false);
  623. rightContent.gameObject.SetActive(false);
  624. LeftBtnClick(1, false);
  625. });
  626. num++;
  627. }
  628. }
  629. }
  630. layerBtn.btn.GetComponent<Button>().onClick.AddListener(() =>
  631. {
  632. for (int j = 0; j < layerBtns.Count; j++)
  633. {
  634. layerBtns[j].SetUseful(false);
  635. layerBtns[j].secContent.gameObject.SetActive(false);
  636. }
  637. layerBtns[index].SetUseful(true);
  638. layerBtns[index].secContent.gameObject.SetActive(true);
  639. //ChangeRuntimeLayer(index);
  640. });
  641. layerBtn.SetLayerBtnData(layerSprite[layerDatas[i].layerID], layerDatas[i].layerName, num.ToString());
  642. layerBtn.GetComponent<RectTransform>().SetParent(content.GetComponent<RectTransform>());
  643. layerBtn.transform.localScale = Vector3.one;
  644. layerBtns.Add(layerBtn);
  645. }
  646. content.GetComponent<VerticalLayoutGroup>().SetLayoutVertical();
  647. layerBtns[0].SetUseful(true);
  648. }
  649. void ChangeRightContent(int index)
  650. {
  651. for (int i = 0; i < infoRight.childCount; i++)
  652. {
  653. infoRight.GetChild(i).gameObject.SetActive(false);
  654. }
  655. infoRight.GetChild(index).gameObject.SetActive(true);
  656. GameObject title = infoRight.GetChild(index).GetChild(0).GetChild(1).gameObject;
  657. GameObject text1 = infoRight.GetChild(index).GetChild(0).GetChild(2).gameObject;
  658. if (title != null)
  659. {
  660. title.GetComponent<Text>().text = GlobalData.layerUnitDatas[index].name;
  661. }
  662. if (text1 != null)
  663. {
  664. text1.GetComponent<Text>().text = GlobalData.layerUnitDatas[index].text1;
  665. }
  666. if (infoRight.GetChild(index).GetChild(0).childCount > 3)
  667. {
  668. GameObject text2 = infoRight.GetChild(index).GetChild(0).GetChild(3).gameObject;
  669. if (text2 != null)
  670. {
  671. text2.GetComponent<Text>().text = GlobalData.layerUnitDatas[index].text2;
  672. }
  673. }
  674. }
  675. void InitPoint()
  676. {
  677. GameObject shaPan = GameObject.FindGameObjectWithTag("ShaPan");
  678. for (int i = 0; i < GlobalData.hotPointDatas.Count; i++)
  679. {
  680. HotPointData temp = GlobalData.hotPointDatas[i];
  681. Vector3 tempLocalPosition = CoordinateConverter.GeoToUGUISmall(temp.longitude, temp.latitude);
  682. //bool have = false;
  683. //for (int j = 0; j < runtimePointLib.Count; j++)
  684. //{
  685. // if (Vector3.Distance(tempLocalPosition, runtimePointLib[j].bingObj.transform.localPosition) < 0.1)
  686. // {
  687. // if (runtimePointLib[j].layerIDs.Contains((int)temp.type))
  688. // {
  689. // have = true;
  690. // break;
  691. // }
  692. // else {
  693. // have = true;
  694. // runtimePointLib[j].Refresh(hotPointSprite[8]);
  695. // runtimePointLib[j].layerIDs.Add((int)temp.type);
  696. // break;
  697. // }
  698. // }
  699. //}
  700. //if (have) {
  701. // continue;
  702. //}
  703. RuntimePoint newPoint = Instantiate(pointPrefab, Vector3.zero, Quaternion.identity);
  704. int tempI = i;
  705. newPoint.GetComponent<RectTransform>().SetParent(pointParent);
  706. newPoint.InitPoint(hotPointSprite[(int)(temp.type)], temp.namePri, temp.name);
  707. newPoint.layerIDs.Add((int)(temp.type));
  708. newPoint.bingObj = Instantiate(runtimePointObj).gameObject;
  709. newPoint.bingObj.transform.SetParent(shaPan.transform.GetChild(8));
  710. newPoint.bingObj.transform.localEulerAngles = Vector3.zero;
  711. newPoint.bingObj.transform.localScale = Vector3.one;
  712. newPoint.bingObj.transform.localPosition = tempLocalPosition;
  713. newPoint.bingObj.name = temp.name;
  714. if ((int)temp.type == 6 || (int)temp.type == 7)
  715. {
  716. int index = FindIndexByLayerUnitName(temp.name);
  717. Item0 item0 = Instantiate(item0Prefab, Vector3.zero, Quaternion.identity);
  718. item0.GetComponent<RectTransform>().SetParent(item0Parent.transform);
  719. item0.InitPoint(hotPointSprite[(int)(temp.type)], temp.namePri, temp.name, GlobalData.layerUnitDatas[index].special);
  720. item0.onPointClick = () =>
  721. {
  722. OnNewPointClick(temp, item0);
  723. };
  724. }
  725. Item0 item1 = Instantiate(item0Prefab, Vector3.zero, Quaternion.identity);
  726. item1.GetComponent<RectTransform>().SetParent(item0Parent.transform);
  727. item1.InitPoint(hotPointSprite[7], "GeTi", "隔提", "1");
  728. //item1.onPointClick = () =>
  729. //{
  730. // OnNewPointClick(temp, item1);
  731. //};
  732. newPoint.onPointClick = () =>
  733. {
  734. OnNewPointClick(temp, newPoint);
  735. };
  736. runtimePointLib.Add(newPoint);
  737. }
  738. RunTimeLayerClick(0);
  739. RunTimeLayerClick(1);
  740. RunTimeLayerClick(2);
  741. RunTimeLayerClick(3);
  742. RunTimeLayerClick(4);
  743. RunTimeLayerClick(5);
  744. RunTimeLayerClick(6);
  745. BaseLayer3BtnOnClick(true);
  746. }
  747. int FindIndexByLayerUnitName(string name)
  748. {
  749. for (int i = 0; i < GlobalData.layerUnitDatas.Count; i++)
  750. {
  751. if (GlobalData.layerUnitDatas[i].name == name.Trim())
  752. {
  753. return i;
  754. }
  755. }
  756. return -1;
  757. }
  758. int FindIndexByHotPointName(string name)
  759. {
  760. Debug.Log(name);
  761. for (int i = 0; i < GlobalData.swDatas.Count; i++)
  762. {
  763. Debug.Log(GlobalData.swDatas[i].STNM);
  764. if (GlobalData.swDatas[i].STNM.Trim() == name.Trim())
  765. {
  766. return i;
  767. }
  768. }
  769. return -1;
  770. }
  771. void OnNewPointClick(HotPointData temp, RuntimePoint newPoint)
  772. {
  773. Debug.Log(temp.type);
  774. if ((int)temp.type == 4)
  775. {
  776. int index = FindIndexByHotPointName(temp.name);
  777. Debug.Log(index);
  778. _waterTrendPanel.Show(GlobalData.swDatas[index].STCD, GlobalData.swDatas[index].STNM);
  779. }
  780. else if ((int)temp.type >= 6 || newPoint.layerIDs.Count > 4)
  781. {
  782. CameraManager.SwitchCamera(0);
  783. viewMode = ViewMode.normal;
  784. StaticLod.instance.OnFoucusStatic(newPoint.staticImp);
  785. yZT.gameObject.SetActive(true);
  786. int index = FindIndexByLayerUnitName(temp.name);
  787. ChangeRightContent(index);
  788. pointParent.gameObject.SetActive(false);
  789. clearBtn.gameObject.SetActive(false);
  790. middleContent.gameObject.SetActive(false);
  791. rightContent.gameObject.SetActive(false);
  792. LeftBtnClick(1, false);
  793. }
  794. }
  795. void OnNewPointClick(HotPointData temp, Item0 item0)
  796. {
  797. CameraManager.SwitchCamera(0);
  798. viewMode = ViewMode.normal;
  799. StaticLod.instance.OnFoucusStatic(item0.staticImp);
  800. yZT.gameObject.SetActive(true);
  801. int index = FindIndexByLayerUnitName(temp.name);
  802. ChangeRightContent(index);
  803. pointParent.gameObject.SetActive(false);
  804. clearBtn.gameObject.SetActive(false);
  805. middleContent.gameObject.SetActive(false);
  806. rightContent.gameObject.SetActive(false);
  807. LeftBtnClick(1, false);
  808. }
  809. async Task InitData()
  810. {
  811. await new WaitUntil(() =>
  812. {
  813. return GlobalData.layerUnitDatas.Count > 0;
  814. });
  815. }
  816. async Task InitPointData()
  817. {
  818. await new WaitUntil(() =>
  819. {
  820. return GlobalData.hotPointDatas.Count > 0;
  821. });
  822. }
  823. void Init()
  824. {
  825. yZT.gameObject.SetActive(false);
  826. clearBtn.gameObject.SetActive(true);
  827. pointParent.gameObject.SetActive(true);
  828. middleContent.gameObject.SetActive(true);
  829. rightContent.gameObject.SetActive(true);
  830. LeftBtnClick(currentActiveLeft);
  831. }
  832. void InitReturnBtn()
  833. {
  834. returnBtn.onClick.AddListener(() =>
  835. {
  836. CameraManager.SwitchCamera(1);
  837. viewMode = ViewMode.miniMap;
  838. Init();
  839. });
  840. }
  841. void ChangeRuntimeLayer(int layer, bool show)
  842. {
  843. if (show)
  844. {
  845. if (cancelLayer.Contains(layer))
  846. {
  847. cancelLayer.Remove(layer);
  848. }
  849. }
  850. else
  851. {
  852. if (!cancelLayer.Contains(layer))
  853. {
  854. cancelLayer.Add(layer);
  855. }
  856. }
  857. for (int i = 0; i < runtimePointLib.Count; i++)
  858. {
  859. if (runtimePointLib[i].layerIDs.Contains(layer))
  860. {
  861. if (runtimePointLib[i].layerIDs.Count < 2)
  862. {
  863. runtimePointLib[i].gameObject.SetActive(show);
  864. }
  865. else
  866. {
  867. List<int> tempLayers = new List<int>(runtimePointLib[i].layerIDs);
  868. for (int j = 0; j < cancelLayer.Count; j++)
  869. {
  870. if (tempLayers.Contains(cancelLayer[j]))
  871. {
  872. tempLayers.Remove(cancelLayer[j]);
  873. }
  874. }
  875. if (tempLayers.Count < 1)
  876. {
  877. runtimePointLib[i].gameObject.SetActive(false);
  878. }
  879. else
  880. {
  881. runtimePointLib[i].gameObject.SetActive(true);
  882. }
  883. }
  884. }
  885. }
  886. }
  887. void ShootRay()
  888. {
  889. Ray ray = CameraManager.instance.mainCamera.ScreenPointToRay(Input.mousePosition);
  890. RaycastHit hit;
  891. if (Physics.Raycast(ray, out hit, 20000, 1 << 8 | 1 << 9))
  892. {
  893. CameraBird bird = CameraManager.instance.mainCamera.GetComponent<CameraBird>();
  894. if (hit.collider.gameObject.layer == LayerMask.NameToLayer("EarthTile"))
  895. {
  896. if (bird.transform.position.y > 1000)
  897. {
  898. bird.SetCameraToCenterFade(hit.point, 1100);
  899. }
  900. }
  901. else if (hit.collider.gameObject.layer == LayerMask.NameToLayer("StaticImportant"))
  902. {
  903. StaticImportant si = hit.collider.gameObject.GetComponent<StaticImportant>();
  904. int index = StaticLod.instance.OnFoucusStatic(si);
  905. yZT.gameObject.SetActive(true);
  906. ChangeRightContent(index);
  907. pointParent.gameObject.SetActive(false);
  908. clearBtn.gameObject.SetActive(false);
  909. middleContent.gameObject.SetActive(false);
  910. rightContent.gameObject.SetActive(false);
  911. LeftBtnClick(1, false);
  912. }
  913. }
  914. else
  915. {
  916. Debug.Log("No hit");
  917. }
  918. }
  919. private void OnEnable()
  920. {
  921. if (regionObjParent != null)
  922. regionObjParent.transform.gameObject.SetActive(true);
  923. if (regionObjParent2 != null)
  924. regionObjParent2.transform.gameObject.SetActive(true);
  925. }
  926. private void OnDisable()
  927. {
  928. if (regionObjParent != null)
  929. regionParent.transform.gameObject.SetActive(false);
  930. if (regionObjParent2 != null)
  931. regionObjParent2.transform.gameObject.SetActive(false);
  932. }
  933. private void Update()
  934. {
  935. if (Input.GetMouseButtonDown(0)) // 检测鼠标左键点击
  936. {
  937. clickInterval = 0.0f;
  938. startClickPosition = Input.mousePosition;
  939. }
  940. clickInterval += Time.deltaTime;
  941. if (Input.GetMouseButtonUp(0))
  942. {
  943. if (clickInterval < 0.2f && Vector3.Distance(startClickPosition, Input.mousePosition) < 10f)
  944. {
  945. if (!CameraManager.instance.secondCamera.enabled)
  946. {
  947. ShootRay();
  948. }
  949. }
  950. }
  951. }
  952. private void LateUpdate()
  953. {
  954. if (CameraManager.instance.secondCamera.enabled)
  955. {
  956. regionParent.transform.gameObject.SetActive(true);
  957. for (int i = 0; i < riverLayerInfo.Length; i++)
  958. {
  959. if (riverLayerInfo[i].gameObject.activeSelf)
  960. {
  961. riverLayerInfo[i].anchoredPosition = CameraManager.instance.secondCamera.WorldToScreenPoint(riverLayerObj[i].transform.position) / Screen.width * 1920.0f;
  962. }
  963. }
  964. for (int i = 0; i < lakeLayerInfo.Length; i++)
  965. {
  966. if (lakeLayerInfo[i].gameObject.activeSelf)
  967. {
  968. lakeLayerInfo[i].anchoredPosition = CameraManager.instance.secondCamera.WorldToScreenPoint(lakeLayerObj[i].transform.position) / Screen.width * 1920.0f;
  969. }
  970. }
  971. }
  972. else
  973. {
  974. regionParent.transform.gameObject.SetActive(false);
  975. }
  976. }
  977. }