YZTLayer.cs 38 KB

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