YZTLayer.cs 39 KB

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