YZTLayer.cs 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918
  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. baseLayerInfoBtns[0].GetComponent<CanvasGroup>().alpha = newActive ? 1f : 0.5f;
  400. if (newActive)
  401. {
  402. BaseLayer2BtnOnClick(false);
  403. BaseLayer3BtnOnClick(false);
  404. }
  405. for (int i = 0; i < regionLayerObj.Length; i++)
  406. {
  407. regionLayerObj[i].gameObject.SetActive(newActive);
  408. regionLayerInfo[i].gameObject.SetActive(newActive);
  409. }
  410. }
  411. void BaseLayer2BtnOnClick(bool newActive)
  412. {
  413. if (newActive)
  414. {
  415. BaseLayer0BtnOnClick(false);
  416. BaseLayer3BtnOnClick(false);
  417. }
  418. baseLayerInfoBtns[2].GetComponent<CanvasGroup>().alpha = newActive ? 1f : 0.5f;
  419. for (int i = 0; i < lakeLayerObj.Length; i++)
  420. {
  421. lakeLayerObj[i].gameObject.SetActive(newActive);
  422. lakeLayerInfo[i].gameObject.SetActive(newActive);
  423. }
  424. }
  425. void BaseLayer3BtnOnClick(bool newActive)
  426. {
  427. if (newActive)
  428. {
  429. BaseLayer0BtnOnClick(false);
  430. BaseLayer2BtnOnClick(false);
  431. }
  432. baseLayerInfoBtns[3].GetComponent<CanvasGroup>().alpha = newActive ? 1f : 0.5f;
  433. for (int i = 0; i < region2LayerObj.Count; i++)
  434. {
  435. region2LayerObj[i].gameObject.SetActive(newActive);
  436. region2LayerInfo[i].gameObject.SetActive(newActive);
  437. }
  438. }
  439. void RunTimeLayerClick(int temp)
  440. {
  441. bool active = layerInfoBtns[temp].GetComponent<CanvasGroup>().alpha > 0.5f;
  442. layerInfoBtns[temp].GetComponent<CanvasGroup>().alpha = active ? 0.5f : 1.0f;
  443. bool newActive = !active;
  444. ChangeRuntimeLayer(temp, newActive);
  445. }
  446. void LeftBtnClick(int index, bool record = true)
  447. {
  448. if (record)
  449. currentActiveLeft = index;
  450. for (int i = 0; i < leftButtons.Length; i++)
  451. {
  452. leftButtons[i].GetComponent<Image>().sprite = sprites[1];
  453. }
  454. leftButtons[index].GetComponent<Image>().sprite = sprites[0];
  455. for (int i = 0; i < leftContent.childCount; i++)
  456. {
  457. leftContent.transform.GetChild(i).gameObject.SetActive(false);
  458. }
  459. leftContent.transform.GetChild(index).gameObject.SetActive(true);
  460. if (index == 1)
  461. {
  462. InitSWHeightInfo();
  463. }
  464. }
  465. void InitLayerBtns()
  466. {
  467. layerBtns = new List<LayerBtn>();
  468. for (int i = 0; i < layerDatas.Length; i++)
  469. {
  470. LayerBtn layerBtn = Instantiate(layerBtnPrefab);
  471. layerBtn.SetUseful(false);
  472. int index = i;
  473. int num = 0;
  474. if (i == 0)
  475. {
  476. List<LayerUnitData> tempDatas = new List<LayerUnitData>(GlobalData.layerUnitDatas);
  477. for (int j = 0; j < tempDatas.Count; j++)
  478. {
  479. if (tempDatas[j].special)
  480. {
  481. int tempJ = j;
  482. SecLayerBtn secLayerBtn = Instantiate(secLayerBtnPrefab);
  483. secLayerBtn.SetLayerBtnData(tempDatas[j].name);
  484. secLayerBtn.GetComponent<RectTransform>().SetParent(layerBtn.secContent.GetComponent<RectTransform>());
  485. secLayerBtn.btn.onClick.AddListener(() =>
  486. {
  487. CameraManager.SwitchCamera(0);
  488. viewMode = ViewMode.normal;
  489. StaticLod.instance.OnFoucusStatic(tempDatas[tempJ].name_pri);
  490. yZT.gameObject.SetActive(true);
  491. ChangeRightContent(tempJ);
  492. pointParent.gameObject.SetActive(false);
  493. clearBtn.gameObject.SetActive(false);
  494. middleContent.gameObject.SetActive(false);
  495. rightContent.gameObject.SetActive(false);
  496. LeftBtnClick(1, false);
  497. });
  498. num++;
  499. }
  500. }
  501. layerBtn.secContent.gameObject.SetActive(true);
  502. }
  503. else
  504. {
  505. List<LayerUnitData> tempDatas = new List<LayerUnitData>(GlobalData.layerUnitDatas);
  506. for (int j = 0; j < tempDatas.Count; j++)
  507. {
  508. if ((int)tempDatas[j].type == layerDatas[i].layerID)
  509. {
  510. int tempJ = j;
  511. SecLayerBtn secLayerBtn = Instantiate(secLayerBtnPrefab);
  512. secLayerBtn.SetLayerBtnData(tempDatas[j].name);
  513. secLayerBtn.GetComponent<RectTransform>().SetParent(layerBtn.secContent.GetComponent<RectTransform>());
  514. secLayerBtn.btn.onClick.AddListener(() =>
  515. {
  516. CameraManager.SwitchCamera(0);
  517. viewMode = ViewMode.normal;
  518. StaticLod.instance.OnFoucusStatic(tempDatas[tempJ].name_pri);
  519. yZT.gameObject.SetActive(true);
  520. ChangeRightContent(tempJ);
  521. pointParent.gameObject.SetActive(false);
  522. clearBtn.gameObject.SetActive(false);
  523. middleContent.gameObject.SetActive(false);
  524. rightContent.gameObject.SetActive(false);
  525. LeftBtnClick(1, false);
  526. });
  527. num++;
  528. }
  529. }
  530. }
  531. layerBtn.btn.GetComponent<Button>().onClick.AddListener(() =>
  532. {
  533. for (int j = 0; j < layerBtns.Count; j++)
  534. {
  535. layerBtns[j].SetUseful(false);
  536. layerBtns[j].secContent.gameObject.SetActive(false);
  537. }
  538. layerBtns[index].SetUseful(true);
  539. layerBtns[index].secContent.gameObject.SetActive(true);
  540. //ChangeRuntimeLayer(index);
  541. });
  542. layerBtn.SetLayerBtnData(layerSprite[layerDatas[i].layerID], layerDatas[i].layerName, num.ToString());
  543. layerBtn.GetComponent<RectTransform>().SetParent(content.GetComponent<RectTransform>());
  544. layerBtn.transform.localScale = Vector3.one;
  545. layerBtns.Add(layerBtn);
  546. }
  547. content.GetComponent<VerticalLayoutGroup>().SetLayoutVertical();
  548. layerBtns[0].SetUseful(true);
  549. }
  550. void ChangeRightContent(int index)
  551. {
  552. for (int i = 0; i < infoRight.childCount; i++)
  553. {
  554. infoRight.GetChild(i).gameObject.SetActive(false);
  555. }
  556. infoRight.GetChild(index).gameObject.SetActive(true);
  557. GameObject title = infoRight.GetChild(index).GetChild(0).GetChild(1).gameObject;
  558. GameObject text1 = infoRight.GetChild(index).GetChild(0).GetChild(2).gameObject;
  559. if (title != null)
  560. {
  561. title.GetComponent<Text>().text = GlobalData.layerUnitDatas[index].name;
  562. }
  563. if (text1 != null)
  564. {
  565. text1.GetComponent<Text>().text = GlobalData.layerUnitDatas[index].text1;
  566. }
  567. if (infoRight.GetChild(index).GetChild(0).childCount > 3)
  568. {
  569. GameObject text2 = infoRight.GetChild(index).GetChild(0).GetChild(3).gameObject;
  570. if (text2 != null)
  571. {
  572. text2.GetComponent<Text>().text = GlobalData.layerUnitDatas[index].text2;
  573. }
  574. }
  575. }
  576. void InitPoint()
  577. {
  578. GameObject shaPan = GameObject.FindGameObjectWithTag("ShaPan");
  579. for (int i = 0; i < GlobalData.hotPointDatas.Count; i++)
  580. {
  581. HotPointData temp = GlobalData.hotPointDatas[i];
  582. Vector3 tempLocalPosition = CoordinateConverter.GeoToUGUISmall(temp.longitude, temp.latitude);
  583. //bool have = false;
  584. //for (int j = 0; j < runtimePointLib.Count; j++)
  585. //{
  586. // if (Vector3.Distance(tempLocalPosition, runtimePointLib[j].bingObj.transform.localPosition) < 0.1)
  587. // {
  588. // if (runtimePointLib[j].layerIDs.Contains((int)temp.type))
  589. // {
  590. // have = true;
  591. // break;
  592. // }
  593. // else {
  594. // have = true;
  595. // runtimePointLib[j].Refresh(hotPointSprite[8]);
  596. // runtimePointLib[j].layerIDs.Add((int)temp.type);
  597. // break;
  598. // }
  599. // }
  600. //}
  601. //if (have) {
  602. // continue;
  603. //}
  604. RuntimePoint newPoint = Instantiate(pointPrefab, Vector3.zero, Quaternion.identity);
  605. int tempI = i;
  606. newPoint.GetComponent<RectTransform>().SetParent(pointParent);
  607. newPoint.InitPoint(hotPointSprite[(int)(temp.type)], temp.name_pri, temp.name); ;
  608. newPoint.layerIDs.Add((int)(temp.type));
  609. newPoint.bingObj = Instantiate(runtimePointObj).gameObject;
  610. newPoint.bingObj.transform.SetParent(shaPan.transform.GetChild(8));
  611. newPoint.bingObj.transform.localEulerAngles = Vector3.zero;
  612. newPoint.bingObj.transform.localScale = Vector3.one;
  613. newPoint.bingObj.transform.localPosition = tempLocalPosition;
  614. newPoint.bingObj.name = temp.name;
  615. newPoint.onPointClick = () =>
  616. {
  617. OnNewPointClick(temp, newPoint);
  618. };
  619. runtimePointLib.Add(newPoint);
  620. }
  621. RunTimeLayerClick(0);
  622. RunTimeLayerClick(1);
  623. RunTimeLayerClick(2);
  624. RunTimeLayerClick(3);
  625. RunTimeLayerClick(4);
  626. RunTimeLayerClick(5);
  627. }
  628. int FindIndexByLayerUnitName(string name)
  629. {
  630. for (int i = 0; i < GlobalData.layerUnitDatas.Count; i++)
  631. {
  632. if (GlobalData.layerUnitDatas[i].name == name.Trim())
  633. {
  634. return i;
  635. }
  636. }
  637. return -1;
  638. }
  639. void OnNewPointClick(HotPointData temp, RuntimePoint newPoint)
  640. {
  641. if ((int)temp.type == 4)
  642. {
  643. OnePicNav.instance.SwitchToGlobalWaterHeight();
  644. }
  645. else if ((int)temp.type >= 6 || newPoint.layerIDs.Count > 4)
  646. {
  647. Debug.Log(1111111111111);
  648. CameraManager.SwitchCamera(0);
  649. viewMode = ViewMode.normal;
  650. StaticLod.instance.OnFoucusStatic(newPoint.staticImp);
  651. yZT.gameObject.SetActive(true);
  652. int index = FindIndexByLayerUnitName(temp.name);
  653. ChangeRightContent(index);
  654. pointParent.gameObject.SetActive(false);
  655. clearBtn.gameObject.SetActive(false);
  656. middleContent.gameObject.SetActive(false);
  657. rightContent.gameObject.SetActive(false);
  658. LeftBtnClick(1, false);
  659. }
  660. }
  661. async Task InitData()
  662. {
  663. await new WaitUntil(() =>
  664. {
  665. return GlobalData.layerUnitDatas.Count > 0;
  666. });
  667. }
  668. async Task InitPointData()
  669. {
  670. await new WaitUntil(() =>
  671. {
  672. return GlobalData.hotPointDatas.Count > 0;
  673. });
  674. }
  675. void Init()
  676. {
  677. yZT.gameObject.SetActive(false);
  678. clearBtn.gameObject.SetActive(true);
  679. pointParent.gameObject.SetActive(true);
  680. middleContent.gameObject.SetActive(true);
  681. rightContent.gameObject.SetActive(true);
  682. LeftBtnClick(currentActiveLeft);
  683. }
  684. void InitReturnBtn()
  685. {
  686. returnBtn.onClick.AddListener(() =>
  687. {
  688. CameraManager.SwitchCamera(1);
  689. viewMode = ViewMode.miniMap;
  690. Init();
  691. });
  692. }
  693. void ChangeRuntimeLayer(int layer, bool show)
  694. {
  695. if (show)
  696. {
  697. if (cancelLayer.Contains(layer))
  698. {
  699. cancelLayer.Remove(layer);
  700. }
  701. }
  702. else
  703. {
  704. if (!cancelLayer.Contains(layer))
  705. {
  706. cancelLayer.Add(layer);
  707. }
  708. }
  709. for (int i = 0; i < runtimePointLib.Count; i++)
  710. {
  711. if (runtimePointLib[i].layerIDs.Contains(layer))
  712. {
  713. if (runtimePointLib[i].layerIDs.Count < 2)
  714. {
  715. runtimePointLib[i].gameObject.SetActive(show);
  716. }
  717. else
  718. {
  719. List<int> tempLayers = new List<int>(runtimePointLib[i].layerIDs);
  720. for (int j = 0; j < cancelLayer.Count; j++)
  721. {
  722. if (tempLayers.Contains(cancelLayer[j]))
  723. {
  724. tempLayers.Remove(cancelLayer[j]);
  725. }
  726. }
  727. if (tempLayers.Count < 1)
  728. {
  729. runtimePointLib[i].gameObject.SetActive(false);
  730. }
  731. else
  732. {
  733. runtimePointLib[i].gameObject.SetActive(true);
  734. }
  735. }
  736. }
  737. }
  738. }
  739. void ShootRay()
  740. {
  741. Ray ray = CameraManager.instance.mainCamera.ScreenPointToRay(Input.mousePosition);
  742. RaycastHit hit;
  743. if (Physics.Raycast(ray, out hit, 20000, 1 << 8 | 1 << 9))
  744. {
  745. CameraBird bird = CameraManager.instance.mainCamera.GetComponent<CameraBird>();
  746. if (hit.collider.gameObject.layer == LayerMask.NameToLayer("EarthTile"))
  747. {
  748. if (bird.transform.position.y > 1000)
  749. {
  750. bird.SetCameraToCenterFade(hit.point, 1100);
  751. }
  752. }
  753. else if (hit.collider.gameObject.layer == LayerMask.NameToLayer("StaticImportant"))
  754. {
  755. StaticImportant si = hit.collider.gameObject.GetComponent<StaticImportant>();
  756. int index = StaticLod.instance.OnFoucusStatic(si);
  757. yZT.gameObject.SetActive(true);
  758. ChangeRightContent(index);
  759. pointParent.gameObject.SetActive(false);
  760. clearBtn.gameObject.SetActive(false);
  761. middleContent.gameObject.SetActive(false);
  762. rightContent.gameObject.SetActive(false);
  763. LeftBtnClick(1, false);
  764. }
  765. }
  766. else
  767. {
  768. Debug.Log("No hit");
  769. }
  770. }
  771. private void OnEnable()
  772. {
  773. regionObjParent.transform.gameObject.SetActive(true);
  774. regionObjParent2.transform.gameObject.SetActive(true);
  775. }
  776. private void OnDisable()
  777. {
  778. regionObjParent.transform.gameObject.SetActive(false);
  779. regionObjParent2.transform.gameObject.SetActive(true);
  780. }
  781. private void Update()
  782. {
  783. if (Input.GetMouseButtonDown(0)) // 检测鼠标左键点击
  784. {
  785. clickInterval = 0.0f;
  786. startClickPosition = Input.mousePosition;
  787. }
  788. clickInterval += Time.deltaTime;
  789. if (Input.GetMouseButtonUp(0))
  790. {
  791. if (clickInterval < 0.2f && Vector3.Distance(startClickPosition, Input.mousePosition) < 10f)
  792. {
  793. if (!CameraManager.instance.secondCamera.enabled)
  794. {
  795. ShootRay();
  796. }
  797. }
  798. }
  799. }
  800. private void LateUpdate()
  801. {
  802. for (int i = 0; i < regionLayerInfo.Length; i++)
  803. {
  804. if (regionLayerInfo[i].gameObject.activeSelf)
  805. {
  806. regionLayerInfo[i].anchoredPosition = CameraManager.instance.secondCamera.WorldToScreenPoint(regionLayerObj[i].transform.position) / Screen.width * 1920.0f;
  807. }
  808. }
  809. for (int i = 0; i < riverLayerInfo.Length; i++)
  810. {
  811. if (riverLayerInfo[i].gameObject.activeSelf)
  812. {
  813. riverLayerInfo[i].anchoredPosition = CameraManager.instance.secondCamera.WorldToScreenPoint(riverLayerObj[i].transform.position) / Screen.width * 1920.0f;
  814. }
  815. }
  816. for (int i = 0; i < lakeLayerInfo.Length; i++)
  817. {
  818. if (lakeLayerInfo[i].gameObject.activeSelf)
  819. {
  820. lakeLayerInfo[i].anchoredPosition = CameraManager.instance.secondCamera.WorldToScreenPoint(lakeLayerObj[i].transform.position) / Screen.width * 1920.0f;
  821. }
  822. }
  823. for (int i = 0; i < region2LayerInfo.Count; i++)
  824. {
  825. if (region2LayerInfo[i].gameObject.activeSelf)
  826. {
  827. region2LayerInfo[i].anchoredPosition = CameraManager.instance.secondCamera.WorldToScreenPoint(region2LayerObj[i].transform.position) / Screen.width * 1920.0f;
  828. }
  829. }
  830. }
  831. }