YZTLayer.cs 31 KB

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