YZTLayer.cs 34 KB

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