YZTLayer.cs 37 KB

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