YZTLayer.cs 37 KB

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