YZTLayer.cs 33 KB

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