YZTLayer.cs 39 KB

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