YZTLayer.cs 31 KB

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