YZTLayer.cs 38 KB

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