YZTLayer.cs 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967
  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. using System.Reflection;
  15. [System.Serializable]
  16. public class YZTLayerData
  17. {
  18. public string layerName;
  19. public int layerID;
  20. }
  21. public enum LayerUnitType
  22. {
  23. ZZ = 1,
  24. BZ,
  25. NC,
  26. QXZ,
  27. JK,
  28. QT
  29. }
  30. [System.Serializable]
  31. public class LayerUnitData
  32. {
  33. public string special;
  34. public LayerUnitType type;
  35. public float longitude;
  36. public float latitude;
  37. public string name;
  38. public string namePri;
  39. public string text1;
  40. public string text2;
  41. public string GetTypeName()
  42. {
  43. string result = "";
  44. switch (type)
  45. {
  46. case LayerUnitType.ZZ:
  47. result = "闸站";
  48. break;
  49. case LayerUnitType.BZ:
  50. result = "泵站";
  51. break;
  52. case LayerUnitType.NC:
  53. result = "农场";
  54. break;
  55. case LayerUnitType.QXZ:
  56. result = "气象站";
  57. break;
  58. case LayerUnitType.JK:
  59. result = "监控";
  60. break;
  61. case LayerUnitType.QT:
  62. result = "其他";
  63. break;
  64. }
  65. return result;
  66. }
  67. }
  68. [System.Serializable]
  69. public class HotPointData
  70. {
  71. public LayerUnitType type;
  72. public float longitude;
  73. public float latitude;
  74. public string name;
  75. public string namePri;
  76. }
  77. [System.Serializable]
  78. public class SWStationRecordData
  79. {
  80. public string name;
  81. public string time;
  82. public float value;
  83. public int dir;
  84. public string stcd = "0";
  85. }
  86. public class YZTLayer : YZTRootLayer
  87. {
  88. public VerticalLayoutGroup content;
  89. public Sprite[] layerSprite;
  90. public Sprite[] hotPointSprite;
  91. public LayerBtn layerBtnPrefab;
  92. public SecLayerBtn secLayerBtnPrefab;
  93. public YZTLayerData[] layerDatas;
  94. public RectTransform leftContent;
  95. public RectTransform middleContent;
  96. public RectTransform rightContent;
  97. List<LayerBtn> layerBtns = new List<LayerBtn>();
  98. public RuntimePoint pointPrefab;
  99. public GameObject runtimePointObj;
  100. public RectTransform pointParent;
  101. List<RuntimePoint> runtimePointLib = new List<RuntimePoint>();
  102. public GameObject yZTMini;
  103. public GameObject yZT;
  104. public RectTransform infoRight;
  105. public Button returnBtn;
  106. private float clickInterval;
  107. private Vector3 startClickPosition;
  108. public Button[] leftButtons;
  109. public Button layerButton;
  110. public int currentActiveLeft = 0;
  111. public RectTransform layerInfo;
  112. public Button layerInfoExitBtn;
  113. public Button[] baseLayerInfoBtns;
  114. public Button[] layerInfoBtns;
  115. public List<int> cancelLayer = new List<int>();
  116. public Sprite[] sprites;
  117. public Text rainText;
  118. public Text[] rainTextNum;
  119. public GameObject thingPrefab;
  120. public RectTransform thingParent;
  121. public List<SWStationRecordData> rescordSWStationData = new List<SWStationRecordData>();
  122. public List<GameObject> thing3s = new List<GameObject>();
  123. public Button clearBtn;
  124. public RectTransform regionParent;
  125. public RectTransform[] riverLayerInfo;
  126. public RectTransform[] lakeLayerInfo;
  127. public GameObject regionObjParent;
  128. public GameObject regionObjParent2;
  129. public GameObject[] regionLayerObj;
  130. public GameObject[] riverLayerObj;
  131. public GameObject[] lakeLayerObj;
  132. public List<GameObject> region2LayerObj = new List<GameObject>();
  133. // Start is called before the first frame update
  134. public WaterTrendPanel _waterTrendPanel;
  135. public Item0 item0Prefab;
  136. public GameObject item0Parent;
  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 < regionObjParent2.transform.childCount; i++)
  384. {
  385. region2LayerObj.Add(regionObjParent2.transform.GetChild(i).gameObject);
  386. }
  387. baseLayerInfoBtns[3].onClick.AddListener(() =>
  388. {
  389. bool active = baseLayerInfoBtns[3].GetComponent<CanvasGroup>().alpha > 0.5f;
  390. BaseLayer3BtnOnClick(!active);
  391. });
  392. baseLayerInfoBtns[3].GetComponent<CanvasGroup>().alpha = 0.5f;
  393. }
  394. void BaseLayer0BtnOnClick(bool newActive)
  395. {
  396. baseLayerInfoBtns[0].GetComponent<CanvasGroup>().alpha = newActive ? 1f : 0.5f;
  397. if (newActive)
  398. {
  399. BaseLayer2BtnOnClick(false);
  400. BaseLayer3BtnOnClick(false);
  401. }
  402. for (int i = 0; i < regionLayerObj.Length; i++)
  403. {
  404. regionLayerObj[i].gameObject.SetActive(newActive);
  405. }
  406. }
  407. void BaseLayer2BtnOnClick(bool newActive)
  408. {
  409. if (newActive)
  410. {
  411. BaseLayer0BtnOnClick(false);
  412. BaseLayer3BtnOnClick(false);
  413. }
  414. baseLayerInfoBtns[2].GetComponent<CanvasGroup>().alpha = newActive ? 1f : 0.5f;
  415. for (int i = 0; i < lakeLayerObj.Length; i++)
  416. {
  417. lakeLayerObj[i].gameObject.SetActive(newActive);
  418. lakeLayerInfo[i].gameObject.SetActive(newActive);
  419. }
  420. }
  421. void BaseLayer3BtnOnClick(bool newActive)
  422. {
  423. if (newActive)
  424. {
  425. BaseLayer0BtnOnClick(false);
  426. BaseLayer2BtnOnClick(false);
  427. }
  428. baseLayerInfoBtns[3].GetComponent<CanvasGroup>().alpha = newActive ? 1f : 0.5f;
  429. for (int i = 0; i < region2LayerObj.Count; i++)
  430. {
  431. region2LayerObj[i].gameObject.SetActive(newActive);
  432. }
  433. }
  434. void RunTimeLayerClick(int temp)
  435. {
  436. bool active = layerInfoBtns[temp].GetComponent<CanvasGroup>().alpha > 0.5f;
  437. layerInfoBtns[temp].GetComponent<CanvasGroup>().alpha = active ? 0.5f : 1.0f;
  438. bool newActive = !active;
  439. ChangeRuntimeLayer(temp, newActive);
  440. }
  441. void LeftBtnClick(int index, bool record = true)
  442. {
  443. if (record)
  444. currentActiveLeft = index;
  445. for (int i = 0; i < leftButtons.Length; i++)
  446. {
  447. leftButtons[i].GetComponent<Image>().sprite = sprites[1];
  448. }
  449. leftButtons[index].GetComponent<Image>().sprite = sprites[0];
  450. for (int i = 0; i < leftContent.childCount; i++)
  451. {
  452. leftContent.transform.GetChild(i).gameObject.SetActive(false);
  453. }
  454. leftContent.transform.GetChild(index).gameObject.SetActive(true);
  455. if (index == 1)
  456. {
  457. InitSWHeightInfo();
  458. }
  459. }
  460. void InitLayerBtns()
  461. {
  462. layerBtns = new List<LayerBtn>();
  463. for (int i = 0; i < layerDatas.Length; i++)
  464. {
  465. LayerBtn layerBtn = Instantiate(layerBtnPrefab);
  466. layerBtn.SetUseful(false);
  467. int index = i;
  468. int num = 0;
  469. if (i == 0)
  470. {
  471. List<LayerUnitData> tempDatas = new List<LayerUnitData>(GlobalData.layerUnitDatas);
  472. for (int j = 0; j < tempDatas.Count; j++)
  473. {
  474. if (tempDatas[j].special == "1")
  475. {
  476. int tempJ = j;
  477. SecLayerBtn secLayerBtn = Instantiate(secLayerBtnPrefab);
  478. secLayerBtn.SetLayerBtnData(tempDatas[j].name);
  479. secLayerBtn.GetComponent<RectTransform>().SetParent(layerBtn.secContent.GetComponent<RectTransform>());
  480. secLayerBtn.btn.onClick.AddListener(() =>
  481. {
  482. CameraManager.SwitchCamera(0);
  483. viewMode = ViewMode.normal;
  484. StaticLod.instance.OnFoucusStatic(tempDatas[tempJ].namePri);
  485. yZT.gameObject.SetActive(true);
  486. ChangeRightContent(tempJ);
  487. pointParent.gameObject.SetActive(false);
  488. clearBtn.gameObject.SetActive(false);
  489. middleContent.gameObject.SetActive(false);
  490. rightContent.gameObject.SetActive(false);
  491. LeftBtnClick(1, false);
  492. });
  493. num++;
  494. }
  495. }
  496. layerBtn.secContent.gameObject.SetActive(true);
  497. }
  498. else
  499. {
  500. List<LayerUnitData> tempDatas = new List<LayerUnitData>(GlobalData.layerUnitDatas);
  501. for (int j = 0; j < tempDatas.Count; j++)
  502. {
  503. if ((int)tempDatas[j].type == layerDatas[i].layerID)
  504. {
  505. int tempJ = j;
  506. SecLayerBtn secLayerBtn = Instantiate(secLayerBtnPrefab);
  507. secLayerBtn.SetLayerBtnData(tempDatas[j].name);
  508. secLayerBtn.GetComponent<RectTransform>().SetParent(layerBtn.secContent.GetComponent<RectTransform>());
  509. secLayerBtn.btn.onClick.AddListener(() =>
  510. {
  511. CameraManager.SwitchCamera(0);
  512. viewMode = ViewMode.normal;
  513. StaticLod.instance.OnFoucusStatic(tempDatas[tempJ].namePri);
  514. yZT.gameObject.SetActive(true);
  515. ChangeRightContent(tempJ);
  516. pointParent.gameObject.SetActive(false);
  517. clearBtn.gameObject.SetActive(false);
  518. middleContent.gameObject.SetActive(false);
  519. rightContent.gameObject.SetActive(false);
  520. LeftBtnClick(1, false);
  521. });
  522. num++;
  523. }
  524. }
  525. }
  526. layerBtn.btn.GetComponent<Button>().onClick.AddListener(() =>
  527. {
  528. for (int j = 0; j < layerBtns.Count; j++)
  529. {
  530. layerBtns[j].SetUseful(false);
  531. layerBtns[j].secContent.gameObject.SetActive(false);
  532. }
  533. layerBtns[index].SetUseful(true);
  534. layerBtns[index].secContent.gameObject.SetActive(true);
  535. //ChangeRuntimeLayer(index);
  536. });
  537. layerBtn.SetLayerBtnData(layerSprite[layerDatas[i].layerID], layerDatas[i].layerName, num.ToString());
  538. layerBtn.GetComponent<RectTransform>().SetParent(content.GetComponent<RectTransform>());
  539. layerBtn.transform.localScale = Vector3.one;
  540. layerBtns.Add(layerBtn);
  541. }
  542. content.GetComponent<VerticalLayoutGroup>().SetLayoutVertical();
  543. layerBtns[0].SetUseful(true);
  544. }
  545. void ChangeRightContent(int index)
  546. {
  547. for (int i = 0; i < infoRight.childCount; i++)
  548. {
  549. infoRight.GetChild(i).gameObject.SetActive(false);
  550. }
  551. infoRight.GetChild(index).gameObject.SetActive(true);
  552. GameObject title = infoRight.GetChild(index).GetChild(0).GetChild(1).gameObject;
  553. GameObject text1 = infoRight.GetChild(index).GetChild(0).GetChild(2).gameObject;
  554. if (title != null)
  555. {
  556. title.GetComponent<Text>().text = GlobalData.layerUnitDatas[index].name;
  557. }
  558. if (text1 != null)
  559. {
  560. text1.GetComponent<Text>().text = GlobalData.layerUnitDatas[index].text1;
  561. }
  562. if (infoRight.GetChild(index).GetChild(0).childCount > 3)
  563. {
  564. GameObject text2 = infoRight.GetChild(index).GetChild(0).GetChild(3).gameObject;
  565. if (text2 != null)
  566. {
  567. text2.GetComponent<Text>().text = GlobalData.layerUnitDatas[index].text2;
  568. }
  569. }
  570. }
  571. void InitPoint()
  572. {
  573. GameObject shaPan = GameObject.FindGameObjectWithTag("ShaPan");
  574. for (int i = 0; i < GlobalData.hotPointDatas.Count; i++)
  575. {
  576. HotPointData temp = GlobalData.hotPointDatas[i];
  577. Vector3 tempLocalPosition = CoordinateConverter.GeoToUGUISmall(temp.longitude, temp.latitude);
  578. //bool have = false;
  579. //for (int j = 0; j < runtimePointLib.Count; j++)
  580. //{
  581. // if (Vector3.Distance(tempLocalPosition, runtimePointLib[j].bingObj.transform.localPosition) < 0.1)
  582. // {
  583. // if (runtimePointLib[j].layerIDs.Contains((int)temp.type))
  584. // {
  585. // have = true;
  586. // break;
  587. // }
  588. // else {
  589. // have = true;
  590. // runtimePointLib[j].Refresh(hotPointSprite[8]);
  591. // runtimePointLib[j].layerIDs.Add((int)temp.type);
  592. // break;
  593. // }
  594. // }
  595. //}
  596. //if (have) {
  597. // continue;
  598. //}
  599. RuntimePoint newPoint = Instantiate(pointPrefab, Vector3.zero, Quaternion.identity);
  600. int tempI = i;
  601. newPoint.GetComponent<RectTransform>().SetParent(pointParent);
  602. newPoint.InitPoint(hotPointSprite[(int)(temp.type)], temp.namePri, temp.name);
  603. newPoint.layerIDs.Add((int)(temp.type));
  604. newPoint.bingObj = Instantiate(runtimePointObj).gameObject;
  605. newPoint.bingObj.transform.SetParent(shaPan.transform.GetChild(8));
  606. newPoint.bingObj.transform.localEulerAngles = Vector3.zero;
  607. newPoint.bingObj.transform.localScale = Vector3.one;
  608. newPoint.bingObj.transform.localPosition = tempLocalPosition;
  609. newPoint.bingObj.name = temp.name;
  610. if ((int)temp.type == 6 || (int)temp.type == 7)
  611. {
  612. int index = FindIndexByLayerUnitName(temp.name);
  613. Item0 item0 = Instantiate(item0Prefab, Vector3.zero, Quaternion.identity);
  614. item0.GetComponent<RectTransform>().SetParent(item0Parent.transform);
  615. item0.InitPoint(hotPointSprite[(int)(temp.type)], temp.namePri, temp.name, GlobalData.layerUnitDatas[index].special);
  616. item0.onPointClick = () =>
  617. {
  618. OnNewPointClick(temp, item0);
  619. };
  620. }
  621. Item0 item1 = Instantiate(item0Prefab, Vector3.zero, Quaternion.identity);
  622. item1.GetComponent<RectTransform>().SetParent(item0Parent.transform);
  623. item1.InitPoint(hotPointSprite[7], "GeTi", "隔提", "1");
  624. //item1.onPointClick = () =>
  625. //{
  626. // OnNewPointClick(temp, item1);
  627. //};
  628. newPoint.onPointClick = () =>
  629. {
  630. OnNewPointClick(temp, newPoint);
  631. };
  632. runtimePointLib.Add(newPoint);
  633. }
  634. RunTimeLayerClick(0);
  635. RunTimeLayerClick(1);
  636. RunTimeLayerClick(2);
  637. RunTimeLayerClick(3);
  638. RunTimeLayerClick(4);
  639. RunTimeLayerClick(5);
  640. RunTimeLayerClick(6);
  641. BaseLayer3BtnOnClick(true);
  642. }
  643. int FindIndexByLayerUnitName(string name)
  644. {
  645. for (int i = 0; i < GlobalData.layerUnitDatas.Count; i++)
  646. {
  647. if (GlobalData.layerUnitDatas[i].name == name.Trim())
  648. {
  649. return i;
  650. }
  651. }
  652. return -1;
  653. }
  654. int FindIndexByHotPointName(string name)
  655. {
  656. Debug.Log(name);
  657. for (int i = 0; i < GlobalData.swDatas.Count; i++)
  658. {
  659. Debug.Log(GlobalData.swDatas[i].STNM);
  660. if (GlobalData.swDatas[i].STNM.Trim() == name.Trim())
  661. {
  662. return i;
  663. }
  664. }
  665. return -1;
  666. }
  667. void OnNewPointClick(HotPointData temp, RuntimePoint newPoint)
  668. {
  669. Debug.Log(temp.type);
  670. if ((int)temp.type == 4)
  671. {
  672. int index = FindIndexByHotPointName(temp.name);
  673. Debug.Log(index);
  674. _waterTrendPanel.Show(GlobalData.swDatas[index].STCD, GlobalData.swDatas[index].STNM);
  675. }
  676. else if ((int)temp.type >= 6 || newPoint.layerIDs.Count > 4)
  677. {
  678. CameraManager.SwitchCamera(0);
  679. viewMode = ViewMode.normal;
  680. StaticLod.instance.OnFoucusStatic(newPoint.staticImp);
  681. yZT.gameObject.SetActive(true);
  682. int index = FindIndexByLayerUnitName(temp.name);
  683. ChangeRightContent(index);
  684. pointParent.gameObject.SetActive(false);
  685. clearBtn.gameObject.SetActive(false);
  686. middleContent.gameObject.SetActive(false);
  687. rightContent.gameObject.SetActive(false);
  688. LeftBtnClick(1, false);
  689. }
  690. }
  691. void OnNewPointClick(HotPointData temp, Item0 item0)
  692. {
  693. CameraManager.SwitchCamera(0);
  694. viewMode = ViewMode.normal;
  695. StaticLod.instance.OnFoucusStatic(item0.staticImp);
  696. yZT.gameObject.SetActive(true);
  697. int index = FindIndexByLayerUnitName(temp.name);
  698. ChangeRightContent(index);
  699. pointParent.gameObject.SetActive(false);
  700. clearBtn.gameObject.SetActive(false);
  701. middleContent.gameObject.SetActive(false);
  702. rightContent.gameObject.SetActive(false);
  703. LeftBtnClick(1, false);
  704. }
  705. async Task InitData()
  706. {
  707. await new WaitUntil(() =>
  708. {
  709. return GlobalData.layerUnitDatas.Count > 0;
  710. });
  711. }
  712. async Task InitPointData()
  713. {
  714. await new WaitUntil(() =>
  715. {
  716. return GlobalData.hotPointDatas.Count > 0;
  717. });
  718. }
  719. void Init()
  720. {
  721. yZT.gameObject.SetActive(false);
  722. clearBtn.gameObject.SetActive(true);
  723. pointParent.gameObject.SetActive(true);
  724. middleContent.gameObject.SetActive(true);
  725. rightContent.gameObject.SetActive(true);
  726. LeftBtnClick(currentActiveLeft);
  727. }
  728. void InitReturnBtn()
  729. {
  730. returnBtn.onClick.AddListener(() =>
  731. {
  732. CameraManager.SwitchCamera(1);
  733. viewMode = ViewMode.miniMap;
  734. Init();
  735. });
  736. }
  737. void ChangeRuntimeLayer(int layer, bool show)
  738. {
  739. if (show)
  740. {
  741. if (cancelLayer.Contains(layer))
  742. {
  743. cancelLayer.Remove(layer);
  744. }
  745. }
  746. else
  747. {
  748. if (!cancelLayer.Contains(layer))
  749. {
  750. cancelLayer.Add(layer);
  751. }
  752. }
  753. for (int i = 0; i < runtimePointLib.Count; i++)
  754. {
  755. if (runtimePointLib[i].layerIDs.Contains(layer))
  756. {
  757. if (runtimePointLib[i].layerIDs.Count < 2)
  758. {
  759. runtimePointLib[i].gameObject.SetActive(show);
  760. }
  761. else
  762. {
  763. List<int> tempLayers = new List<int>(runtimePointLib[i].layerIDs);
  764. for (int j = 0; j < cancelLayer.Count; j++)
  765. {
  766. if (tempLayers.Contains(cancelLayer[j]))
  767. {
  768. tempLayers.Remove(cancelLayer[j]);
  769. }
  770. }
  771. if (tempLayers.Count < 1)
  772. {
  773. runtimePointLib[i].gameObject.SetActive(false);
  774. }
  775. else
  776. {
  777. runtimePointLib[i].gameObject.SetActive(true);
  778. }
  779. }
  780. }
  781. }
  782. }
  783. void ShootRay()
  784. {
  785. Ray ray = CameraManager.instance.mainCamera.ScreenPointToRay(Input.mousePosition);
  786. RaycastHit hit;
  787. if (Physics.Raycast(ray, out hit, 20000, 1 << 8 | 1 << 9))
  788. {
  789. CameraBird bird = CameraManager.instance.mainCamera.GetComponent<CameraBird>();
  790. if (hit.collider.gameObject.layer == LayerMask.NameToLayer("EarthTile"))
  791. {
  792. if (bird.transform.position.y > 1000)
  793. {
  794. bird.SetCameraToCenterFade(hit.point, 1100);
  795. }
  796. }
  797. else if (hit.collider.gameObject.layer == LayerMask.NameToLayer("StaticImportant"))
  798. {
  799. StaticImportant si = hit.collider.gameObject.GetComponent<StaticImportant>();
  800. int index = StaticLod.instance.OnFoucusStatic(si);
  801. yZT.gameObject.SetActive(true);
  802. ChangeRightContent(index);
  803. pointParent.gameObject.SetActive(false);
  804. clearBtn.gameObject.SetActive(false);
  805. middleContent.gameObject.SetActive(false);
  806. rightContent.gameObject.SetActive(false);
  807. LeftBtnClick(1, false);
  808. }
  809. }
  810. else
  811. {
  812. Debug.Log("No hit");
  813. }
  814. }
  815. private void OnEnable()
  816. {
  817. if (regionObjParent != null)
  818. regionObjParent.transform.gameObject.SetActive(true);
  819. if (regionObjParent2 != null)
  820. regionObjParent2.transform.gameObject.SetActive(true);
  821. }
  822. private void OnDisable()
  823. {
  824. if (regionObjParent != null)
  825. regionParent.transform.gameObject.SetActive(false);
  826. if (regionObjParent2 != null)
  827. regionObjParent2.transform.gameObject.SetActive(false);
  828. }
  829. private void Update()
  830. {
  831. if (Input.GetMouseButtonDown(0)) // 检测鼠标左键点击
  832. {
  833. clickInterval = 0.0f;
  834. startClickPosition = Input.mousePosition;
  835. }
  836. clickInterval += Time.deltaTime;
  837. if (Input.GetMouseButtonUp(0))
  838. {
  839. if (clickInterval < 0.2f && Vector3.Distance(startClickPosition, Input.mousePosition) < 10f)
  840. {
  841. if (!CameraManager.instance.secondCamera.enabled)
  842. {
  843. ShootRay();
  844. }
  845. }
  846. }
  847. }
  848. private void LateUpdate()
  849. {
  850. if (CameraManager.instance.secondCamera.enabled)
  851. {
  852. regionParent.transform.gameObject.SetActive(true);
  853. for (int i = 0; i < riverLayerInfo.Length; i++)
  854. {
  855. if (riverLayerInfo[i].gameObject.activeSelf)
  856. {
  857. riverLayerInfo[i].anchoredPosition = CameraManager.instance.secondCamera.WorldToScreenPoint(riverLayerObj[i].transform.position) / Screen.width * 1920.0f;
  858. }
  859. }
  860. for (int i = 0; i < lakeLayerInfo.Length; i++)
  861. {
  862. if (lakeLayerInfo[i].gameObject.activeSelf)
  863. {
  864. lakeLayerInfo[i].anchoredPosition = CameraManager.instance.secondCamera.WorldToScreenPoint(lakeLayerObj[i].transform.position) / Screen.width * 1920.0f;
  865. }
  866. }
  867. }
  868. else
  869. {
  870. regionParent.transform.gameObject.SetActive(false);
  871. }
  872. }
  873. }