YZTLayer.cs 33 KB

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