YZTLayer.cs 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133
  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. sWStationRecordData.time = DateTime.Now.ToString("MM/dd HH:mm");
  336. sWStationRecordData.stcd = GlobalData.swDatas[i].stcd;
  337. rescordSWStationData.Add(sWStationRecordData);
  338. }
  339. for (int i = 0; i < rescordSWStationData.Count; i++)
  340. {
  341. GameObject obj = Instantiate(thingPrefab);
  342. obj.GetComponent<RectTransform>().SetParent(thingParent);
  343. obj.transform.localScale = Vector3.one;
  344. obj.transform.GetChild(0).GetComponent<Text>().text = (i + 1).ToString();
  345. string rescordSW_name = rescordSWStationData[i].name.ToString(); ;
  346. obj.transform.GetChild(1).GetComponent<Text>().text = rescordSW_name;
  347. obj.transform.GetChild(2).GetComponent<Text>().text = rescordSWStationData[i].time.ToString();
  348. obj.transform.GetChild(3).GetComponent<Text>().text = rescordSWStationData[i].value.ToString();
  349. string rescordSW_stcd = rescordSWStationData[i].stcd;
  350. obj.transform.GetComponent<Button>().onClick.AddListener(() =>
  351. {
  352. _waterTrendPanel.ShowTrend(rescordSW_stcd, rescordSW_name,0);
  353. });
  354. if (rescordSWStationData[i].dir == 0)
  355. {
  356. obj.transform.GetChild(4).localEulerAngles = new Vector3(0, 0, 0);
  357. }
  358. else if (rescordSWStationData[i].dir == 1)
  359. {
  360. obj.transform.GetChild(4).localEulerAngles = new Vector3(0, 0, 90);
  361. }
  362. else
  363. {
  364. obj.transform.GetChild(4).localEulerAngles = new Vector3(0, 0, -90);
  365. }
  366. thing3s.Add(obj);
  367. }
  368. }
  369. else
  370. {
  371. for (int i = 0; i < GlobalData.swDatas.Count; i++)
  372. {
  373. rescordSWStationData[i].name = GlobalData.swDatas[i].stnm;
  374. float lastValue = rescordSWStationData[i].value;
  375. rescordSWStationData[i].value = ((GlobalData.swDatas[i].upz ?? 0) > (GlobalData.swDatas[i].dwz ?? 0)) ? GlobalData.swDatas[i].upz ?? 0 : GlobalData.swDatas[i].dwz ?? 0;
  376. rescordSWStationData[i].time = DateTime.Now.ToString("MM/dd HH:mm");
  377. if (rescordSWStationData[i].value > lastValue)
  378. {
  379. rescordSWStationData[i].dir = 1;
  380. }
  381. else if (rescordSWStationData[i].value > lastValue)
  382. {
  383. rescordSWStationData[i].dir = 0;
  384. }
  385. else
  386. {
  387. rescordSWStationData[i].dir = -1;
  388. }
  389. }
  390. for (int i = 0; i < rescordSWStationData.Count; i++)
  391. {
  392. thing3s[i].transform.GetChild(0).GetComponent<Text>().text = (i + 1).ToString();
  393. thing3s[i].transform.GetChild(1).GetComponent<Text>().text = rescordSWStationData[i].name.ToString();
  394. thing3s[i].transform.GetChild(2).GetComponent<Text>().text = rescordSWStationData[i].time.ToString();
  395. thing3s[i].transform.GetChild(3).GetComponent<Text>().text = rescordSWStationData[i].value.ToString();
  396. if (rescordSWStationData[i].dir == 0)
  397. {
  398. thing3s[i].transform.GetChild(4).localEulerAngles = new Vector3(0, 0, 0);
  399. }
  400. else if (rescordSWStationData[i].dir == 1)
  401. {
  402. thing3s[i].transform.GetChild(4).localEulerAngles = new Vector3(0, 0, 90);
  403. }
  404. else
  405. {
  406. thing3s[i].transform.GetChild(4).localEulerAngles = new Vector3(0, 0, -90);
  407. }
  408. }
  409. }
  410. }
  411. async void InitRainInfo()
  412. {
  413. await new WaitUntil(() =>
  414. {
  415. return GlobalData.sWZDatas.Count > 0;
  416. });
  417. int swzCount = GlobalData.sWZDatas.Count;
  418. string maxName = "";
  419. float maxValue = -99f;
  420. int value010 = 0;
  421. int value1025 = 0;
  422. int value2550 = 0;
  423. int value50100 = 0;
  424. int value100200 = 0;
  425. int value200 = 0;
  426. for (int i = 0; i < swzCount; i++)
  427. {
  428. float value = GlobalData.sWZDatas[i].dropSum6;
  429. if (value > maxValue)
  430. {
  431. maxValue = value;
  432. maxName = GlobalData.sWZDatas[i].STNM;
  433. }
  434. if (value >= 0 && value < 10)
  435. {
  436. value010++;
  437. }
  438. else if (value >= 10 && value < 25)
  439. {
  440. value1025++;
  441. }
  442. else if (value >= 25 && value < 50)
  443. {
  444. value2550++;
  445. }
  446. else if (value >= 50 && value < 100)
  447. {
  448. value50100++;
  449. }
  450. else if (value >= 100 && value < 200)
  451. {
  452. value100200++;
  453. }
  454. else
  455. {
  456. value200++;
  457. }
  458. }
  459. rainText.text = $"数据时间:(过去24小时)\r\n蓄洪区共有{swzCount}个雨量站,其中几个雨量站监测有降雨最大降雨测站为{maxName}站点,降雨量{maxValue}mm.";
  460. rainTextNum[0].text = value010.ToString();
  461. rainTextNum[1].text = value1025.ToString();
  462. rainTextNum[2].text = value2550.ToString();
  463. rainTextNum[3].text = value50100.ToString();
  464. rainTextNum[4].text = value100200.ToString();
  465. rainTextNum[5].text = value200.ToString();
  466. }
  467. void InitLayerInfo()
  468. {
  469. //layerInfoBtns = layerInfo.GetComponentsInChildren<Button>();
  470. for (int i = 0; i < layerInfoBtns.Length; i++)
  471. {
  472. int temp = i;
  473. layerInfoBtns[i].onClick.AddListener(() =>
  474. {
  475. RunTimeLayerClick(temp);
  476. });
  477. }
  478. layerButton.onClick.AddListener(() =>
  479. {
  480. layerInfo.gameObject.SetActive(true);
  481. });
  482. layerInfoExitBtn.onClick.AddListener(() =>
  483. {
  484. layerInfo.gameObject.SetActive(false);
  485. });
  486. baseLayerInfoBtns[0].onClick.AddListener(() =>
  487. {
  488. bool active = baseLayerInfoBtns[0].GetComponent<CanvasGroup>().alpha > 0.5f;
  489. BaseLayer0BtnOnClick(!active);
  490. });
  491. baseLayerInfoBtns[0].GetComponent<CanvasGroup>().alpha = 0.5f;
  492. baseLayerInfoBtns[1].onClick.AddListener(() =>
  493. {
  494. bool active = baseLayerInfoBtns[1].GetComponent<CanvasGroup>().alpha > 0.5f;
  495. baseLayerInfoBtns[1].GetComponent<CanvasGroup>().alpha = active ? 0.5f : 1.0f;
  496. bool newActive = !active;
  497. for (int i = 0; i < riverLayerObj.Length; i++)
  498. {
  499. riverLayerObj[i].gameObject.SetActive(newActive);
  500. riverLayerInfo[i].gameObject.SetActive(newActive);
  501. }
  502. });
  503. baseLayerInfoBtns[1].GetComponent<CanvasGroup>().alpha = 0.5f;
  504. baseLayerInfoBtns[2].onClick.AddListener(() =>
  505. {
  506. bool active = baseLayerInfoBtns[2].GetComponent<CanvasGroup>().alpha > 0.5f;
  507. BaseLayer2BtnOnClick(!active);
  508. });
  509. baseLayerInfoBtns[2].GetComponent<CanvasGroup>().alpha = 0.5f;
  510. for (int i = 0; i < regionObjParent2.transform.childCount; i++)
  511. {
  512. region2LayerObj.Add(regionObjParent2.transform.GetChild(i).gameObject);
  513. }
  514. baseLayerInfoBtns[3].onClick.AddListener(() =>
  515. {
  516. bool active = baseLayerInfoBtns[3].GetComponent<CanvasGroup>().alpha > 0.5f;
  517. BaseLayer3BtnOnClick(!active);
  518. });
  519. baseLayerInfoBtns[3].GetComponent<CanvasGroup>().alpha = 0.5f;
  520. }
  521. void BaseLayer0BtnOnClick(bool newActive)
  522. {
  523. baseLayerInfoBtns[0].GetComponent<CanvasGroup>().alpha = newActive ? 1f : 0.5f;
  524. if (newActive)
  525. {
  526. //BaseLayer2BtnOnClick(false);
  527. //BaseLayer3BtnOnClick(false);
  528. }
  529. for (int i = 0; i < regionLayerObj.Length; i++)
  530. {
  531. regionLayerObj[i].gameObject.SetActive(newActive);
  532. }
  533. }
  534. void BaseLayer2BtnOnClick(bool newActive)
  535. {
  536. if (newActive)
  537. {
  538. //BaseLayer0BtnOnClick(false);
  539. //BaseLayer3BtnOnClick(false);
  540. }
  541. baseLayerInfoBtns[2].GetComponent<CanvasGroup>().alpha = newActive ? 1f : 0.5f;
  542. for (int i = 0; i < lakeLayerObj.Length; i++)
  543. {
  544. lakeLayerObj[i].gameObject.SetActive(newActive);
  545. lakeLayerInfo[i].gameObject.SetActive(newActive);
  546. }
  547. }
  548. void BaseLayer3BtnOnClick(bool newActive)
  549. {
  550. if (newActive)
  551. {
  552. //BaseLayer0BtnOnClick(false);
  553. //BaseLayer2BtnOnClick(false);
  554. }
  555. baseLayerInfoBtns[3].GetComponent<CanvasGroup>().alpha = newActive ? 1f : 0.5f;
  556. for (int i = 0; i < region2LayerObj.Count; i++)
  557. {
  558. region2LayerObj[i].gameObject.SetActive(newActive);
  559. }
  560. }
  561. void RunTimeLayerClick(int temp)
  562. {
  563. bool active = layerInfoBtns[temp].GetComponent<CanvasGroup>().alpha > 0.5f;
  564. layerInfoBtns[temp].GetComponent<CanvasGroup>().alpha = active ? 0.5f : 1.0f;
  565. bool newActive = !active;
  566. ChangeRuntimeLayer(temp, newActive);
  567. }
  568. void LeftBtnClick(int index, bool record = true)
  569. {
  570. if (record)
  571. currentActiveLeft = index;
  572. for (int i = 0; i < leftButtons.Length; i++)
  573. {
  574. leftButtons[i].GetComponent<Image>().sprite = sprites[1];
  575. }
  576. leftButtons[index].GetComponent<Image>().sprite = sprites[0];
  577. for (int i = 0; i < leftContent.childCount; i++)
  578. {
  579. leftContent.transform.GetChild(i).gameObject.SetActive(false);
  580. }
  581. leftContent.transform.GetChild(index).gameObject.SetActive(true);
  582. if (index == 1)
  583. {
  584. InitSWHeightInfo();
  585. }
  586. }
  587. void InitLayerBtns()
  588. {
  589. layerBtns = new List<LayerBtn>();
  590. for (int i = 0; i < layerDatas.Length; i++)
  591. {
  592. LayerBtn layerBtn = Instantiate(layerBtnPrefab);
  593. layerBtn.SetUseful(false);
  594. int index = i;
  595. int num = 0;
  596. if (i == 0)
  597. {
  598. List<LayerUnitData> tempDatas = new List<LayerUnitData>(GlobalData.layerUnitDatas);
  599. for (int j = 0; j < tempDatas.Count; j++)
  600. {
  601. if (tempDatas[j].special == "1")
  602. {
  603. int tempJ = j;
  604. SecLayerBtn secLayerBtn = Instantiate(secLayerBtnPrefab);
  605. secLayerBtn.SetLayerBtnData(tempDatas[j].name);
  606. secLayerBtn.GetComponent<RectTransform>().SetParent(layerBtn.secContent.GetComponent<RectTransform>());
  607. secLayerBtn.btn.onClick.AddListener(() =>
  608. {
  609. CameraManager.SwitchCamera(0);
  610. viewMode = ViewMode.normal;
  611. StaticLod.instance.OnFoucusStatic(tempDatas[tempJ].namePri);
  612. yZT.gameObject.SetActive(true);
  613. ChangeRightContent(tempJ);
  614. pointParent.gameObject.SetActive(false);
  615. clearBtn.gameObject.SetActive(false);
  616. middleContent.gameObject.SetActive(false);
  617. rightContent.gameObject.SetActive(false);
  618. LeftBtnClick(1, false);
  619. });
  620. num++;
  621. }
  622. }
  623. layerBtn.secContent.gameObject.SetActive(true);
  624. }
  625. else
  626. {
  627. List<LayerUnitData> tempDatas = new List<LayerUnitData>(GlobalData.layerUnitDatas);
  628. for (int j = 0; j < tempDatas.Count; j++)
  629. {
  630. if ((int)tempDatas[j].type == layerDatas[i].layerID)
  631. {
  632. int tempJ = j;
  633. SecLayerBtn secLayerBtn = Instantiate(secLayerBtnPrefab);
  634. secLayerBtn.SetLayerBtnData(tempDatas[j].name);
  635. secLayerBtn.GetComponent<RectTransform>().SetParent(layerBtn.secContent.GetComponent<RectTransform>());
  636. secLayerBtn.btn.onClick.AddListener(() =>
  637. {
  638. CameraManager.SwitchCamera(0);
  639. viewMode = ViewMode.normal;
  640. StaticLod.instance.OnFoucusStatic(tempDatas[tempJ].namePri);
  641. yZT.gameObject.SetActive(true);
  642. ChangeRightContent(tempJ);
  643. pointParent.gameObject.SetActive(false);
  644. clearBtn.gameObject.SetActive(false);
  645. middleContent.gameObject.SetActive(false);
  646. rightContent.gameObject.SetActive(false);
  647. LeftBtnClick(1, false);
  648. });
  649. num++;
  650. }
  651. }
  652. }
  653. layerBtn.btn.GetComponent<Button>().onClick.AddListener(() =>
  654. {
  655. for (int j = 0; j < layerBtns.Count; j++)
  656. {
  657. layerBtns[j].SetUseful(false);
  658. layerBtns[j].secContent.gameObject.SetActive(false);
  659. }
  660. layerBtns[index].SetUseful(true);
  661. layerBtns[index].secContent.gameObject.SetActive(true);
  662. //ChangeRuntimeLayer(index);
  663. });
  664. layerBtn.SetLayerBtnData(layerSprite[layerDatas[i].layerID], layerDatas[i].layerName, num.ToString());
  665. layerBtn.GetComponent<RectTransform>().SetParent(content.GetComponent<RectTransform>());
  666. layerBtn.transform.localScale = Vector3.one;
  667. layerBtns.Add(layerBtn);
  668. }
  669. content.GetComponent<VerticalLayoutGroup>().SetLayoutVertical();
  670. layerBtns[0].SetUseful(true);
  671. }
  672. void ChangeRightContent(int index)
  673. {
  674. for (int i = 0; i < infoRight.childCount; i++)
  675. {
  676. infoRight.GetChild(i).gameObject.SetActive(false);
  677. }
  678. infoRight.GetChild(index).gameObject.SetActive(true);
  679. GameObject title = infoRight.GetChild(index).GetChild(0).GetChild(1).gameObject;
  680. GameObject text1 = infoRight.GetChild(index).GetChild(0).GetChild(2).gameObject;
  681. if (title != null)
  682. {
  683. title.GetComponent<Text>().text = GlobalData.layerUnitDatas[index].name;
  684. }
  685. if (text1 != null)
  686. {
  687. text1.GetComponent<Text>().text = GlobalData.layerUnitDatas[index].text1;
  688. }
  689. if (infoRight.GetChild(index).GetChild(0).childCount > 3)
  690. {
  691. GameObject text2 = infoRight.GetChild(index).GetChild(0).GetChild(3).gameObject;
  692. if (text2 != null)
  693. {
  694. text2.GetComponent<Text>().text = GlobalData.layerUnitDatas[index].text2;
  695. }
  696. }
  697. }
  698. void InitPoint()
  699. {
  700. GameObject shaPan = GameObject.FindGameObjectWithTag("ShaPan");
  701. List<Item0> item0s = new List<Item0>();
  702. for (int i = 0; i < GlobalData.hotPointDatas.Count; i++)
  703. {
  704. //if()
  705. HotPointData temp = GlobalData.hotPointDatas[i];
  706. Vector3 tempLocalPosition = CoordinateConverter.GeoToUGUISmall(temp.longitude, temp.latitude);
  707. RuntimePoint newPoint = Instantiate(pointPrefab, Vector3.zero, Quaternion.identity);
  708. int tempI = i;
  709. newPoint.GetComponent<RectTransform>().SetParent(pointParent);
  710. newPoint.InitPoint(hotPointSprite[(int)(temp.type)], temp.namePri, temp.name, temp.longitude, temp.latitude);
  711. newPoint.layerIDs.Add((int)(temp.type));
  712. newPoint.bingObj = Instantiate(runtimePointObj).gameObject;
  713. newPoint.bingObj.transform.SetParent(shaPan.transform.GetChild(8));
  714. newPoint.bingObj.transform.localEulerAngles = Vector3.zero;
  715. newPoint.bingObj.transform.localScale = Vector3.one;
  716. newPoint.bingObj.transform.localPosition = tempLocalPosition;
  717. newPoint.bingObj.name = temp.name;
  718. if ((int)temp.type == 6 || (int)temp.type == 7)
  719. {
  720. int index = FindIndexByLayerUnitName(temp.name);
  721. Item0 item0 = Instantiate(item0Prefab, Vector3.zero, Quaternion.identity);
  722. item0.InitPoint(hotPointSprite[(int)(temp.type)], temp.namePri, temp.name, GlobalData.layerUnitDatas[index].special);
  723. item0s.Add(item0);
  724. item0.onPointClick = () =>
  725. {
  726. OnNewPointClick(temp, item0);
  727. };
  728. }
  729. newPoint.onPointClick = () =>
  730. {
  731. OnNewPointClick(temp, newPoint);
  732. };
  733. runtimePointLib.Add(newPoint);
  734. }
  735. for (int i = 0; i < item0s.Count; i++)
  736. {
  737. if (item0s[i].mSpecial != "1")
  738. item0s[i].GetComponent<RectTransform>().SetParent(item0Parent.transform);
  739. }
  740. for (int i = 0; i < item0s.Count; i++)
  741. {
  742. if (item0s[i].mSpecial == "1")
  743. item0s[i].GetComponent<RectTransform>().SetParent(item0Parent.transform);
  744. }
  745. Item0 item1 = Instantiate(item0Prefab, Vector3.zero, Quaternion.identity);
  746. item1.GetComponent<RectTransform>().SetParent(item0Parent.transform);
  747. item1.InitPoint(hotPointSprite[7], "GeTi", "隔提", "1");
  748. RunTimeLayerClick(0);
  749. RunTimeLayerClick(1);
  750. RunTimeLayerClick(2);
  751. RunTimeLayerClick(3);
  752. RunTimeLayerClick(4);
  753. RunTimeLayerClick(5);
  754. RunTimeLayerClick(6);
  755. RunTimeLayerClick(8);
  756. BaseLayer0BtnOnClick(true);
  757. }
  758. int FindIndexByLayerUnitName(string name)
  759. {
  760. for (int i = 0; i < GlobalData.layerUnitDatas.Count; i++)
  761. {
  762. if (GlobalData.layerUnitDatas[i].name == name.Trim())
  763. {
  764. return i;
  765. }
  766. }
  767. return -1;
  768. }
  769. public static int FindIndexByHotPointName(string name)
  770. {
  771. string newName = name.Replace("(闸下)", "(闸下)").Replace("(闸上)", "(闸上)");
  772. newName = newName.TrimEnd();
  773. if (newName.Contains("补元"))
  774. {
  775. newName = "补元(闸上)";
  776. }
  777. else if (newName.Contains("套口"))
  778. {
  779. newName = "套口(闸上)";
  780. }
  781. //Debug.Log(newName);
  782. for (int i = 0; i < GlobalData.swDatas.Count; i++)
  783. {
  784. //Debug.Log(GlobalData.swDatas[i].stnm);
  785. if (GlobalData.swDatas[i].stnm.Trim() == newName.Trim())
  786. {
  787. return i;
  788. }
  789. }
  790. return -1;
  791. }
  792. public static int FindIndexBySWName(string name)
  793. {
  794. //string newName = name.Replace("(闸下)", "(下)").Replace("(闸上)", "(上)").Replace("(闸上)", "上").Replace("(闸下)", "下");
  795. //newName = newName.TrimEnd();
  796. //if (newName.Contains("补元"))
  797. //{
  798. // newName = "补元(上)";
  799. //}
  800. //else if (newName.Contains("套口"))
  801. //{
  802. // newName = "套口(上)";
  803. //}
  804. //Debug.Log(newName);
  805. for (int i = 0; i < GlobalData.sWZDatas.Count; i++)
  806. {
  807. //Debug.Log(GlobalData.swDatas[i].stnm);
  808. if (GlobalData.sWZDatas[i].STNM.Trim() == name.Trim())
  809. {
  810. return i;
  811. }
  812. }
  813. return -1;
  814. }
  815. void OnNewPointClick(HotPointData temp, RuntimePoint newPoint)
  816. {
  817. Debug.Log(temp.type);
  818. if ((int)temp.type == 4)
  819. {
  820. int index = FindIndexByHotPointName(temp.name);
  821. Debug.Log(GlobalData.swDatas[index].stcd);
  822. _waterTrendPanel.ShowTrend(GlobalData.swDatas[index].stcd, GlobalData.swDatas[index].stnm,0);
  823. }
  824. else if ((int)temp.type == 2) {
  825. int index = FindIndexBySWName(temp.name);
  826. Debug.Log(index);
  827. _waterTrendPanel.ShowTrend(GlobalData.sWZDatas[index].STCD, GlobalData.sWZDatas[index].STNM,1);
  828. }
  829. else if ((int)temp.type >= 6 || newPoint.layerIDs.Count > 4)
  830. {
  831. CameraManager.SwitchCamera(0);
  832. viewMode = ViewMode.normal;
  833. StaticLod.instance.OnFoucusStatic(newPoint.staticImp);
  834. yZT.gameObject.SetActive(true);
  835. int index = FindIndexByLayerUnitName(temp.name);
  836. ChangeRightContent(index);
  837. pointParent.gameObject.SetActive(false);
  838. clearBtn.gameObject.SetActive(false);
  839. middleContent.gameObject.SetActive(false);
  840. rightContent.gameObject.SetActive(false);
  841. LeftBtnClick(1, false);
  842. }
  843. }
  844. void OnNewPointClick(HotPointData temp, Item0 item0)
  845. {
  846. CameraManager.SwitchCamera(0);
  847. viewMode = ViewMode.normal;
  848. StaticLod.instance.OnFoucusStatic(item0.staticImp);
  849. yZT.gameObject.SetActive(true);
  850. int index = FindIndexByLayerUnitName(temp.name);
  851. ChangeRightContent(index);
  852. pointParent.gameObject.SetActive(false);
  853. clearBtn.gameObject.SetActive(false);
  854. middleContent.gameObject.SetActive(false);
  855. rightContent.gameObject.SetActive(false);
  856. LeftBtnClick(1, false);
  857. }
  858. async Task InitData()
  859. {
  860. await new WaitUntil(() =>
  861. {
  862. return GlobalData.layerUnitDatas.Count > 0;
  863. });
  864. }
  865. async Task InitPointData()
  866. {
  867. await new WaitUntil(() =>
  868. {
  869. return GlobalData.hotPointDatas.Count > 0;
  870. });
  871. }
  872. void Init()
  873. {
  874. yZT.gameObject.SetActive(false);
  875. clearBtn.gameObject.SetActive(true);
  876. pointParent.gameObject.SetActive(true);
  877. middleContent.gameObject.SetActive(true);
  878. rightContent.gameObject.SetActive(true);
  879. LeftBtnClick(currentActiveLeft);
  880. }
  881. void InitReturnBtn()
  882. {
  883. returnBtn.onClick.AddListener(() =>
  884. {
  885. CameraManager.SwitchCamera(1);
  886. viewMode = ViewMode.miniMap;
  887. Init();
  888. });
  889. }
  890. void ChangeRuntimeLayer(int layer, bool show)
  891. {
  892. if (show)
  893. {
  894. if (cancelLayer.Contains(layer))
  895. {
  896. cancelLayer.Remove(layer);
  897. }
  898. }
  899. else
  900. {
  901. if (!cancelLayer.Contains(layer))
  902. {
  903. cancelLayer.Add(layer);
  904. }
  905. }
  906. for (int i = 0; i < runtimePointLib.Count; i++)
  907. {
  908. if (runtimePointLib[i].layerIDs.Contains(layer))
  909. {
  910. if (runtimePointLib[i].layerIDs.Count < 2)
  911. {
  912. runtimePointLib[i].gameObject.SetActive(show);
  913. }
  914. else
  915. {
  916. List<int> tempLayers = new List<int>(runtimePointLib[i].layerIDs);
  917. for (int j = 0; j < cancelLayer.Count; j++)
  918. {
  919. if (tempLayers.Contains(cancelLayer[j]))
  920. {
  921. tempLayers.Remove(cancelLayer[j]);
  922. }
  923. }
  924. if (tempLayers.Count < 1)
  925. {
  926. runtimePointLib[i].gameObject.SetActive(false);
  927. }
  928. else
  929. {
  930. runtimePointLib[i].gameObject.SetActive(true);
  931. }
  932. }
  933. }
  934. }
  935. }
  936. void ShootRay()
  937. {
  938. Ray ray = CameraManager.instance.mainCamera.ScreenPointToRay(Input.mousePosition);
  939. RaycastHit hit;
  940. if (Physics.Raycast(ray, out hit, 20000, 1 << 8 | 1 << 9))
  941. {
  942. CameraBird bird = CameraManager.instance.mainCamera.GetComponent<CameraBird>();
  943. if (hit.collider.gameObject.layer == LayerMask.NameToLayer("EarthTile"))
  944. {
  945. if (bird.transform.position.y > 1000)
  946. {
  947. bird.SetCameraToCenterFade(hit.point, 1100);
  948. }
  949. }
  950. else if (hit.collider.gameObject.layer == LayerMask.NameToLayer("StaticImportant"))
  951. {
  952. StaticImportant si = hit.collider.gameObject.GetComponent<StaticImportant>();
  953. int index = StaticLod.instance.OnFoucusStatic(si);
  954. yZT.gameObject.SetActive(true);
  955. ChangeRightContent(index);
  956. pointParent.gameObject.SetActive(false);
  957. clearBtn.gameObject.SetActive(false);
  958. middleContent.gameObject.SetActive(false);
  959. rightContent.gameObject.SetActive(false);
  960. LeftBtnClick(1, false);
  961. }
  962. }
  963. else
  964. {
  965. Debug.Log("No hit");
  966. }
  967. }
  968. private void OnEnable()
  969. {
  970. if (regionObjParent != null)
  971. regionObjParent.transform.gameObject.SetActive(true);
  972. if (regionObjParent2 != null)
  973. regionObjParent2.transform.gameObject.SetActive(true);
  974. }
  975. private void OnDisable()
  976. {
  977. if (regionObjParent != null)
  978. regionParent.transform.gameObject.SetActive(false);
  979. if (regionObjParent2 != null)
  980. regionObjParent2.transform.gameObject.SetActive(false);
  981. }
  982. private void Update()
  983. {
  984. if (Input.GetMouseButtonDown(0)) // 检测鼠标左键点击
  985. {
  986. clickInterval = 0.0f;
  987. startClickPosition = Input.mousePosition;
  988. }
  989. clickInterval += Time.deltaTime;
  990. if (Input.GetMouseButtonUp(0))
  991. {
  992. if (clickInterval < 0.2f && Vector3.Distance(startClickPosition, Input.mousePosition) < 10f)
  993. {
  994. if (!CameraManager.instance.secondCamera.enabled)
  995. {
  996. ShootRay();
  997. }
  998. }
  999. }
  1000. }
  1001. private void LateUpdate()
  1002. {
  1003. if (CameraManager.instance.secondCamera.enabled)
  1004. {
  1005. regionParent.transform.gameObject.SetActive(true);
  1006. for (int i = 0; i < riverLayerInfo.Length; i++)
  1007. {
  1008. if (riverLayerInfo[i].gameObject.activeSelf)
  1009. {
  1010. riverLayerInfo[i].anchoredPosition = CameraManager.instance.secondCamera.WorldToScreenPoint(riverLayerObj[i].transform.position) / Screen.width * 1920.0f;
  1011. }
  1012. }
  1013. for (int i = 0; i < lakeLayerInfo.Length; i++)
  1014. {
  1015. if (lakeLayerInfo[i].gameObject.activeSelf)
  1016. {
  1017. lakeLayerInfo[i].anchoredPosition = CameraManager.instance.secondCamera.WorldToScreenPoint(lakeLayerObj[i].transform.position) / Screen.width * 1920.0f;
  1018. }
  1019. }
  1020. }
  1021. else
  1022. {
  1023. regionParent.transform.gameObject.SetActive(false);
  1024. }
  1025. }
  1026. }