YZTLayer.cs 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933
  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. void OnNewPointClick(HotPointData temp, RuntimePoint newPoint)
  641. {
  642. if ((int)temp.type == 4)
  643. {
  644. OnePicNav.instance.SwitchToGlobalWaterHeight();
  645. }
  646. else if ((int)temp.type >= 6 || newPoint.layerIDs.Count > 4)
  647. {
  648. Debug.Log(1111111111111);
  649. CameraManager.SwitchCamera(0);
  650. viewMode = ViewMode.normal;
  651. StaticLod.instance.OnFoucusStatic(newPoint.staticImp);
  652. yZT.gameObject.SetActive(true);
  653. int index = FindIndexByLayerUnitName(temp.name);
  654. ChangeRightContent(index);
  655. pointParent.gameObject.SetActive(false);
  656. clearBtn.gameObject.SetActive(false);
  657. middleContent.gameObject.SetActive(false);
  658. rightContent.gameObject.SetActive(false);
  659. LeftBtnClick(1, false);
  660. }
  661. }
  662. async Task InitData()
  663. {
  664. await new WaitUntil(() =>
  665. {
  666. return GlobalData.layerUnitDatas.Count > 0;
  667. });
  668. }
  669. async Task InitPointData()
  670. {
  671. await new WaitUntil(() =>
  672. {
  673. return GlobalData.hotPointDatas.Count > 0;
  674. });
  675. }
  676. void Init()
  677. {
  678. yZT.gameObject.SetActive(false);
  679. clearBtn.gameObject.SetActive(true);
  680. pointParent.gameObject.SetActive(true);
  681. middleContent.gameObject.SetActive(true);
  682. rightContent.gameObject.SetActive(true);
  683. LeftBtnClick(currentActiveLeft);
  684. }
  685. void InitReturnBtn()
  686. {
  687. returnBtn.onClick.AddListener(() =>
  688. {
  689. CameraManager.SwitchCamera(1);
  690. viewMode = ViewMode.miniMap;
  691. Init();
  692. });
  693. }
  694. void ChangeRuntimeLayer(int layer, bool show)
  695. {
  696. if (show)
  697. {
  698. if (cancelLayer.Contains(layer))
  699. {
  700. cancelLayer.Remove(layer);
  701. }
  702. }
  703. else
  704. {
  705. if (!cancelLayer.Contains(layer))
  706. {
  707. cancelLayer.Add(layer);
  708. }
  709. }
  710. for (int i = 0; i < runtimePointLib.Count; i++)
  711. {
  712. if (runtimePointLib[i].layerIDs.Contains(layer))
  713. {
  714. if (runtimePointLib[i].layerIDs.Count < 2)
  715. {
  716. runtimePointLib[i].gameObject.SetActive(show);
  717. }
  718. else
  719. {
  720. List<int> tempLayers = new List<int>(runtimePointLib[i].layerIDs);
  721. for (int j = 0; j < cancelLayer.Count; j++)
  722. {
  723. if (tempLayers.Contains(cancelLayer[j]))
  724. {
  725. tempLayers.Remove(cancelLayer[j]);
  726. }
  727. }
  728. if (tempLayers.Count < 1)
  729. {
  730. runtimePointLib[i].gameObject.SetActive(false);
  731. }
  732. else
  733. {
  734. runtimePointLib[i].gameObject.SetActive(true);
  735. }
  736. }
  737. }
  738. }
  739. }
  740. void ShootRay()
  741. {
  742. Ray ray = CameraManager.instance.mainCamera.ScreenPointToRay(Input.mousePosition);
  743. RaycastHit hit;
  744. if (Physics.Raycast(ray, out hit, 20000, 1 << 8 | 1 << 9))
  745. {
  746. CameraBird bird = CameraManager.instance.mainCamera.GetComponent<CameraBird>();
  747. if (hit.collider.gameObject.layer == LayerMask.NameToLayer("EarthTile"))
  748. {
  749. if (bird.transform.position.y > 1000)
  750. {
  751. bird.SetCameraToCenterFade(hit.point, 1100);
  752. }
  753. }
  754. else if (hit.collider.gameObject.layer == LayerMask.NameToLayer("StaticImportant"))
  755. {
  756. StaticImportant si = hit.collider.gameObject.GetComponent<StaticImportant>();
  757. int index = StaticLod.instance.OnFoucusStatic(si);
  758. yZT.gameObject.SetActive(true);
  759. ChangeRightContent(index);
  760. pointParent.gameObject.SetActive(false);
  761. clearBtn.gameObject.SetActive(false);
  762. middleContent.gameObject.SetActive(false);
  763. rightContent.gameObject.SetActive(false);
  764. LeftBtnClick(1, false);
  765. }
  766. }
  767. else
  768. {
  769. Debug.Log("No hit");
  770. }
  771. }
  772. private void OnEnable()
  773. {
  774. if (regionObjParent != null)
  775. regionObjParent.transform.gameObject.SetActive(true);
  776. if (regionObjParent2 != null)
  777. regionObjParent2.transform.gameObject.SetActive(true);
  778. }
  779. private void OnDisable()
  780. {
  781. if (regionObjParent != null)
  782. regionParent.transform.gameObject.SetActive(false);
  783. if (regionObjParent2 != null)
  784. regionObjParent2.transform.gameObject.SetActive(false);
  785. }
  786. private void Update()
  787. {
  788. if (Input.GetMouseButtonDown(0)) // 检测鼠标左键点击
  789. {
  790. clickInterval = 0.0f;
  791. startClickPosition = Input.mousePosition;
  792. }
  793. clickInterval += Time.deltaTime;
  794. if (Input.GetMouseButtonUp(0))
  795. {
  796. if (clickInterval < 0.2f && Vector3.Distance(startClickPosition, Input.mousePosition) < 10f)
  797. {
  798. if (!CameraManager.instance.secondCamera.enabled)
  799. {
  800. ShootRay();
  801. }
  802. }
  803. }
  804. }
  805. private void LateUpdate()
  806. {
  807. if (CameraManager.instance.secondCamera.enabled)
  808. {
  809. regionParent.transform.gameObject.SetActive(true);
  810. regionParent2.transform.gameObject.SetActive(true);
  811. for (int i = 0; i < regionLayerInfo.Length; i++)
  812. {
  813. if (regionLayerInfo[i].gameObject.activeSelf)
  814. {
  815. regionLayerInfo[i].anchoredPosition = CameraManager.instance.secondCamera.WorldToScreenPoint(regionLayerObj[i].transform.position) / Screen.width * 1920.0f;
  816. }
  817. }
  818. for (int i = 0; i < riverLayerInfo.Length; i++)
  819. {
  820. if (riverLayerInfo[i].gameObject.activeSelf)
  821. {
  822. riverLayerInfo[i].anchoredPosition = CameraManager.instance.secondCamera.WorldToScreenPoint(riverLayerObj[i].transform.position) / Screen.width * 1920.0f;
  823. }
  824. }
  825. for (int i = 0; i < lakeLayerInfo.Length; i++)
  826. {
  827. if (lakeLayerInfo[i].gameObject.activeSelf)
  828. {
  829. lakeLayerInfo[i].anchoredPosition = CameraManager.instance.secondCamera.WorldToScreenPoint(lakeLayerObj[i].transform.position) / Screen.width * 1920.0f;
  830. }
  831. }
  832. for (int i = 0; i < region2LayerInfo.Count; i++)
  833. {
  834. if (region2LayerInfo[i].gameObject.activeSelf)
  835. {
  836. region2LayerInfo[i].anchoredPosition = CameraManager.instance.secondCamera.WorldToScreenPoint(region2LayerObj[i].transform.position) / Screen.width * 1920.0f;
  837. }
  838. }
  839. }
  840. else
  841. {
  842. regionParent.transform.gameObject.SetActive(false);
  843. regionParent2.transform.gameObject.SetActive(false);
  844. }
  845. }
  846. }