YZTLayer.cs 32 KB

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