YZTLayer.cs 34 KB

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