YZTLayer.cs 40 KB

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