YZTLayer.cs 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099
  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. string newName = name.Replace("(闸下)", "(下)").Replace("(闸上)", "(上)").Replace("(闸上)", "上").Replace("(闸下)", "下");
  775. newName = newName.TrimEnd();
  776. Debug.Log(newName);
  777. for (int i = 0; i < GlobalData.swDatas.Count; i++)
  778. {
  779. //Debug.Log(GlobalData.swDatas[i].stnm);
  780. if (GlobalData.swDatas[i].stnm.Trim() == newName.Trim())
  781. {
  782. return i;
  783. }
  784. }
  785. return -1;
  786. }
  787. void OnNewPointClick(HotPointData temp, RuntimePoint newPoint)
  788. {
  789. Debug.Log(temp.type);
  790. if ((int)temp.type == 4)
  791. {
  792. int index = FindIndexByHotPointName(temp.name);
  793. Debug.Log(index);
  794. _waterTrendPanel.Show(GlobalData.swDatas[index].stcd, GlobalData.swDatas[index].stnm);
  795. }
  796. else if ((int)temp.type >= 6 || newPoint.layerIDs.Count > 4)
  797. {
  798. CameraManager.SwitchCamera(0);
  799. viewMode = ViewMode.normal;
  800. StaticLod.instance.OnFoucusStatic(newPoint.staticImp);
  801. yZT.gameObject.SetActive(true);
  802. int index = FindIndexByLayerUnitName(temp.name);
  803. ChangeRightContent(index);
  804. pointParent.gameObject.SetActive(false);
  805. clearBtn.gameObject.SetActive(false);
  806. middleContent.gameObject.SetActive(false);
  807. rightContent.gameObject.SetActive(false);
  808. LeftBtnClick(1, false);
  809. }
  810. }
  811. void OnNewPointClick(HotPointData temp, Item0 item0)
  812. {
  813. CameraManager.SwitchCamera(0);
  814. viewMode = ViewMode.normal;
  815. StaticLod.instance.OnFoucusStatic(item0.staticImp);
  816. yZT.gameObject.SetActive(true);
  817. int index = FindIndexByLayerUnitName(temp.name);
  818. ChangeRightContent(index);
  819. pointParent.gameObject.SetActive(false);
  820. clearBtn.gameObject.SetActive(false);
  821. middleContent.gameObject.SetActive(false);
  822. rightContent.gameObject.SetActive(false);
  823. LeftBtnClick(1, false);
  824. }
  825. async Task InitData()
  826. {
  827. await new WaitUntil(() =>
  828. {
  829. return GlobalData.layerUnitDatas.Count > 0;
  830. });
  831. }
  832. async Task InitPointData()
  833. {
  834. await new WaitUntil(() =>
  835. {
  836. return GlobalData.hotPointDatas.Count > 0;
  837. });
  838. }
  839. void Init()
  840. {
  841. yZT.gameObject.SetActive(false);
  842. clearBtn.gameObject.SetActive(true);
  843. pointParent.gameObject.SetActive(true);
  844. middleContent.gameObject.SetActive(true);
  845. rightContent.gameObject.SetActive(true);
  846. LeftBtnClick(currentActiveLeft);
  847. }
  848. void InitReturnBtn()
  849. {
  850. returnBtn.onClick.AddListener(() =>
  851. {
  852. CameraManager.SwitchCamera(1);
  853. viewMode = ViewMode.miniMap;
  854. Init();
  855. });
  856. }
  857. void ChangeRuntimeLayer(int layer, bool show)
  858. {
  859. if (show)
  860. {
  861. if (cancelLayer.Contains(layer))
  862. {
  863. cancelLayer.Remove(layer);
  864. }
  865. }
  866. else
  867. {
  868. if (!cancelLayer.Contains(layer))
  869. {
  870. cancelLayer.Add(layer);
  871. }
  872. }
  873. for (int i = 0; i < runtimePointLib.Count; i++)
  874. {
  875. if (runtimePointLib[i].layerIDs.Contains(layer))
  876. {
  877. if (runtimePointLib[i].layerIDs.Count < 2)
  878. {
  879. runtimePointLib[i].gameObject.SetActive(show);
  880. }
  881. else
  882. {
  883. List<int> tempLayers = new List<int>(runtimePointLib[i].layerIDs);
  884. for (int j = 0; j < cancelLayer.Count; j++)
  885. {
  886. if (tempLayers.Contains(cancelLayer[j]))
  887. {
  888. tempLayers.Remove(cancelLayer[j]);
  889. }
  890. }
  891. if (tempLayers.Count < 1)
  892. {
  893. runtimePointLib[i].gameObject.SetActive(false);
  894. }
  895. else
  896. {
  897. runtimePointLib[i].gameObject.SetActive(true);
  898. }
  899. }
  900. }
  901. }
  902. }
  903. void ShootRay()
  904. {
  905. Ray ray = CameraManager.instance.mainCamera.ScreenPointToRay(Input.mousePosition);
  906. RaycastHit hit;
  907. if (Physics.Raycast(ray, out hit, 20000, 1 << 8 | 1 << 9))
  908. {
  909. CameraBird bird = CameraManager.instance.mainCamera.GetComponent<CameraBird>();
  910. if (hit.collider.gameObject.layer == LayerMask.NameToLayer("EarthTile"))
  911. {
  912. if (bird.transform.position.y > 1000)
  913. {
  914. bird.SetCameraToCenterFade(hit.point, 1100);
  915. }
  916. }
  917. else if (hit.collider.gameObject.layer == LayerMask.NameToLayer("StaticImportant"))
  918. {
  919. StaticImportant si = hit.collider.gameObject.GetComponent<StaticImportant>();
  920. int index = StaticLod.instance.OnFoucusStatic(si);
  921. yZT.gameObject.SetActive(true);
  922. ChangeRightContent(index);
  923. pointParent.gameObject.SetActive(false);
  924. clearBtn.gameObject.SetActive(false);
  925. middleContent.gameObject.SetActive(false);
  926. rightContent.gameObject.SetActive(false);
  927. LeftBtnClick(1, false);
  928. }
  929. }
  930. else
  931. {
  932. Debug.Log("No hit");
  933. }
  934. }
  935. private void OnEnable()
  936. {
  937. if (regionObjParent != null)
  938. regionObjParent.transform.gameObject.SetActive(true);
  939. if (regionObjParent2 != null)
  940. regionObjParent2.transform.gameObject.SetActive(true);
  941. }
  942. private void OnDisable()
  943. {
  944. if (regionObjParent != null)
  945. regionParent.transform.gameObject.SetActive(false);
  946. if (regionObjParent2 != null)
  947. regionObjParent2.transform.gameObject.SetActive(false);
  948. }
  949. private void Update()
  950. {
  951. if (Input.GetMouseButtonDown(0)) // 检测鼠标左键点击
  952. {
  953. clickInterval = 0.0f;
  954. startClickPosition = Input.mousePosition;
  955. }
  956. clickInterval += Time.deltaTime;
  957. if (Input.GetMouseButtonUp(0))
  958. {
  959. if (clickInterval < 0.2f && Vector3.Distance(startClickPosition, Input.mousePosition) < 10f)
  960. {
  961. if (!CameraManager.instance.secondCamera.enabled)
  962. {
  963. ShootRay();
  964. }
  965. }
  966. }
  967. }
  968. private void LateUpdate()
  969. {
  970. if (CameraManager.instance.secondCamera.enabled)
  971. {
  972. regionParent.transform.gameObject.SetActive(true);
  973. for (int i = 0; i < riverLayerInfo.Length; i++)
  974. {
  975. if (riverLayerInfo[i].gameObject.activeSelf)
  976. {
  977. riverLayerInfo[i].anchoredPosition = CameraManager.instance.secondCamera.WorldToScreenPoint(riverLayerObj[i].transform.position) / Screen.width * 1920.0f;
  978. }
  979. }
  980. for (int i = 0; i < lakeLayerInfo.Length; i++)
  981. {
  982. if (lakeLayerInfo[i].gameObject.activeSelf)
  983. {
  984. lakeLayerInfo[i].anchoredPosition = CameraManager.instance.secondCamera.WorldToScreenPoint(lakeLayerObj[i].transform.position) / Screen.width * 1920.0f;
  985. }
  986. }
  987. }
  988. else
  989. {
  990. regionParent.transform.gameObject.SetActive(false);
  991. }
  992. }
  993. }