YZTLayer.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719
  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. [System.Serializable]
  14. public class YZTLayerData
  15. {
  16. public string layerName;
  17. public int layerID;
  18. }
  19. public enum LayerUnitType
  20. {
  21. ZZ = 1,
  22. BZ,
  23. NC,
  24. QXZ,
  25. JK,
  26. QT
  27. }
  28. [System.Serializable]
  29. public class LayerUnitData
  30. {
  31. public bool special;
  32. public LayerUnitType type;
  33. public float longitude;
  34. public float latitude;
  35. public string name;
  36. public string name_pri;
  37. public string text1;
  38. public string text2;
  39. public string GetTypeName()
  40. {
  41. string result = "";
  42. switch (type)
  43. {
  44. case LayerUnitType.ZZ:
  45. result = "闸站";
  46. break;
  47. case LayerUnitType.BZ:
  48. result = "泵站";
  49. break;
  50. case LayerUnitType.NC:
  51. result = "农场";
  52. break;
  53. case LayerUnitType.QXZ:
  54. result = "气象站";
  55. break;
  56. case LayerUnitType.JK:
  57. result = "监控";
  58. break;
  59. case LayerUnitType.QT:
  60. result = "其他";
  61. break;
  62. }
  63. return result;
  64. }
  65. }
  66. [System.Serializable]
  67. public class HotPointData
  68. {
  69. public LayerUnitType type;
  70. public float longitude;
  71. public float latitude;
  72. public string name;
  73. public string name_pri;
  74. }
  75. [System.Serializable]
  76. public class SWStationRecordData
  77. {
  78. public string name;
  79. public string time;
  80. public float value;
  81. public int dir;
  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 List<int> cancelLayer = new List<int>();
  111. public Sprite[] sprites;
  112. public Text rainText;
  113. public Text[] rainTextNum;
  114. public GameObject thingPrefab;
  115. public RectTransform thingParent;
  116. public List<SWStationRecordData> rescordSWStationData = new List<SWStationRecordData>();
  117. public List<GameObject> thing3s = new List<GameObject>();
  118. public Button clearBtn;
  119. // Start is called before the first frame update
  120. async void Awake()
  121. {
  122. viewMode = ViewMode.miniMap;
  123. await InitData();
  124. Init();
  125. InitLeftBtn();
  126. InitLayerInfo();
  127. InitLayerBtns();
  128. InitReturnBtn();
  129. InitRainInfo();
  130. InitSWHeightInfo();
  131. await InitPointData();
  132. InitPoint();
  133. }
  134. void InitLeftBtn() {
  135. for (int i = 0; i < leftButtons.Length; i++) {
  136. int temp = i;
  137. leftButtons[i].onClick.AddListener(() =>
  138. {
  139. LeftBtnClick(temp);
  140. });
  141. }
  142. LeftBtnClick(0);
  143. clearBtn.onClick.AddListener(() => {
  144. if (clearBtn.GetComponent<Image>().sprite == sprites[0])
  145. {
  146. clearBtn.GetComponent<Image>().sprite = sprites[1];
  147. leftContent.gameObject.SetActive(false);
  148. middleContent.gameObject.SetActive(false);
  149. rightContent.gameObject.SetActive(false);
  150. clearBtn.GetComponent<RectTransform>().anchoredPosition = new Vector2(-827, clearBtn.GetComponent<RectTransform>().anchoredPosition.y);
  151. }
  152. else {
  153. clearBtn.GetComponent<Image>().sprite = sprites[0];
  154. leftContent.gameObject.SetActive(true);
  155. middleContent.gameObject.SetActive(true);
  156. rightContent.gameObject.SetActive(true);
  157. clearBtn.GetComponent<RectTransform>().anchoredPosition = new Vector2(-457, clearBtn.GetComponent<RectTransform>().anchoredPosition.y);
  158. }
  159. });
  160. }
  161. async void InitSWHeightInfo() {
  162. await new WaitUntil(() => {
  163. return GlobalData.swDatas.Count > 0;
  164. });
  165. if (rescordSWStationData.Count < 1)
  166. {
  167. for (int i = 0; i < GlobalData.swDatas.Count; i++) {
  168. SWStationRecordData sWStationRecordData = new SWStationRecordData();
  169. sWStationRecordData.dir = 0;
  170. sWStationRecordData.name = GlobalData.swDatas[i].STNM;
  171. sWStationRecordData.value = (GlobalData.swDatas[i].upz > GlobalData.swDatas[i].dwz)?GlobalData.swDatas[i].upz:GlobalData.swDatas[i].dwz;
  172. sWStationRecordData.time = DateTime.Now.ToString("MM/dd HH:mm");
  173. rescordSWStationData.Add(sWStationRecordData);
  174. }
  175. for (int i = 0; i < rescordSWStationData.Count; i++)
  176. {
  177. GameObject obj = Instantiate(thingPrefab);
  178. obj.GetComponent<RectTransform>().SetParent(thingParent);
  179. obj.transform.localScale = Vector3.one;
  180. obj.transform.GetChild(0).GetComponent<Text>().text = (i + 1).ToString();
  181. obj.transform.GetChild(1).GetComponent<Text>().text = rescordSWStationData[i].name.ToString();
  182. obj.transform.GetChild(2).GetComponent<Text>().text = rescordSWStationData[i].time.ToString();
  183. obj.transform.GetChild(3).GetComponent<Text>().text = rescordSWStationData[i].value.ToString();
  184. if (rescordSWStationData[i].dir == 0)
  185. {
  186. obj.transform.GetChild(4).localEulerAngles = new Vector3(0, 0, 0);
  187. }
  188. else if (rescordSWStationData[i].dir == 1)
  189. {
  190. obj.transform.GetChild(4).localEulerAngles = new Vector3(0, 0, 90);
  191. }
  192. else {
  193. obj.transform.GetChild(4).localEulerAngles = new Vector3(0, 0, -90);
  194. }
  195. thing3s.Add(obj);
  196. }
  197. }
  198. else {
  199. for (int i = 0; i < GlobalData.swDatas.Count; i++)
  200. {
  201. rescordSWStationData[i].name = GlobalData.swDatas[i].STNM;
  202. float lastValue = rescordSWStationData[i].value;
  203. rescordSWStationData[i].value = (GlobalData.swDatas[i].upz > GlobalData.swDatas[i].dwz) ? GlobalData.swDatas[i].upz : GlobalData.swDatas[i].dwz;
  204. rescordSWStationData[i].time = DateTime.Now.ToString("MM/dd HH:mm");
  205. if (rescordSWStationData[i].value > lastValue)
  206. {
  207. rescordSWStationData[i].dir = 1;
  208. }
  209. else if (rescordSWStationData[i].value > lastValue)
  210. {
  211. rescordSWStationData[i].dir = 0;
  212. }
  213. else {
  214. rescordSWStationData[i].dir = -1;
  215. }
  216. }
  217. for (int i = 0; i < rescordSWStationData.Count; i++)
  218. {
  219. thing3s[i].transform.GetChild(0).GetComponent<Text>().text = (i + 1).ToString();
  220. thing3s[i].transform.GetChild(1).GetComponent<Text>().text = rescordSWStationData[i].name.ToString();
  221. thing3s[i].transform.GetChild(2).GetComponent<Text>().text = rescordSWStationData[i].time.ToString();
  222. thing3s[i].transform.GetChild(3).GetComponent<Text>().text = rescordSWStationData[i].value.ToString();
  223. if (rescordSWStationData[i].dir == 0)
  224. {
  225. thing3s[i].transform.GetChild(4).localEulerAngles = new Vector3(0, 0, 0);
  226. }
  227. else if (rescordSWStationData[i].dir == 1)
  228. {
  229. thing3s[i].transform.GetChild(4).localEulerAngles = new Vector3(0, 0, 90);
  230. }
  231. else
  232. {
  233. thing3s[i].transform.GetChild(4).localEulerAngles = new Vector3(0, 0, -90);
  234. }
  235. }
  236. }
  237. }
  238. async void InitRainInfo() {
  239. await new WaitUntil(() => {
  240. return GlobalData.qXZDatas.Count > 0;
  241. });
  242. int qxzCount = GlobalData.qXZDatas.Count;
  243. string maxName = "";
  244. float maxValue = -99f;
  245. int value010 = 0;
  246. int value1025 = 0;
  247. int value2550 = 0;
  248. int value50100 = 0;
  249. int value100200 = 0;
  250. int value200 = 0;
  251. for (int i = 0; i < qxzCount; i++) {
  252. float value = GlobalData.qXZDatas[i].dropSum6;
  253. if (value > maxValue) {
  254. maxValue = value;
  255. maxName = GlobalData.qXZDatas[i].STNM;
  256. }
  257. if (value >= 0 && value < 10)
  258. {
  259. value010++;
  260. }
  261. else if (value >= 10 && value < 25)
  262. {
  263. value1025++;
  264. }
  265. else if (value >= 25 && value < 50)
  266. {
  267. value2550++;
  268. }
  269. else if (value >= 50 && value < 100)
  270. {
  271. value50100++;
  272. }
  273. else if (value >= 100 && value < 200)
  274. {
  275. value100200++;
  276. }
  277. else
  278. {
  279. value200++;
  280. }
  281. }
  282. rainText.text = $"数据时间:17日12时至18日12时(过去24小时)\r\n蓄洪区共有{qxzCount}个雨量站,其中几个雨量站监测有降雨最大降雨测站为{maxName}站点,降雨量{maxValue}mm.";
  283. rainTextNum[0].text = value010.ToString();
  284. rainTextNum[1].text = value1025.ToString();
  285. rainTextNum[2].text = value2550.ToString();
  286. rainTextNum[3].text = value50100.ToString();
  287. rainTextNum[4].text = value100200.ToString();
  288. rainTextNum[5].text = value200.ToString();
  289. }
  290. void InitLayerInfo() {
  291. Button[] btns = layerInfo.GetComponentsInChildren<Button>();
  292. for (int i = 0; i < btns.Length - 2; i++) {
  293. int temp = i;
  294. btns[i].onClick.AddListener(() =>
  295. {
  296. bool active = btns[temp].GetComponent<CanvasGroup>().alpha > 0.5f;
  297. btns[temp].GetComponent<CanvasGroup>().alpha = active ? 0.5f : 1.0f;
  298. bool newActive = !active;
  299. ChangeRuntimeLayer(temp, newActive);
  300. });
  301. }
  302. layerButton.onClick.AddListener(() => {
  303. layerInfo.gameObject.SetActive(true);
  304. });
  305. layerInfoExitBtn.onClick.AddListener(() =>
  306. {
  307. layerInfo.gameObject.SetActive(false);
  308. });
  309. }
  310. void LeftBtnClick(int index,bool record = true) {
  311. if(record)
  312. currentActiveLeft = index;
  313. for (int i = 0; i < leftButtons.Length; i++)
  314. {
  315. leftButtons[i].GetComponent<Image>().sprite = sprites[1];
  316. }
  317. leftButtons[index].GetComponent<Image>().sprite = sprites[0];
  318. for (int i = 0; i < leftContent.childCount; i++) {
  319. leftContent.transform.GetChild(i).gameObject.SetActive(false);
  320. }
  321. leftContent.transform.GetChild(index).gameObject.SetActive(true);
  322. if (index == 1) {
  323. InitSWHeightInfo();
  324. }
  325. }
  326. void InitLayerBtns()
  327. {
  328. layerBtns = new List<LayerBtn>();
  329. for (int i = 0; i < layerDatas.Length; i++)
  330. {
  331. LayerBtn layerBtn = Instantiate(layerBtnPrefab);
  332. layerBtn.SetUseful(false);
  333. int index = i;
  334. int num = 0;
  335. if (i == 0)
  336. {
  337. List<LayerUnitData> tempDatas = new List<LayerUnitData>(GlobalData.layerUnitDatas);
  338. for (int j = 0; j < tempDatas.Count; j++)
  339. {
  340. if (tempDatas[j].special)
  341. {
  342. int tempJ = j;
  343. SecLayerBtn secLayerBtn = Instantiate(secLayerBtnPrefab);
  344. secLayerBtn.SetLayerBtnData(tempDatas[j].name);
  345. secLayerBtn.GetComponent<RectTransform>().SetParent(layerBtn.secContent.GetComponent<RectTransform>());
  346. secLayerBtn.btn.onClick.AddListener(() => {
  347. CameraManager.SwitchCamera(0);
  348. viewMode = ViewMode.normal;
  349. StaticLod.instance.OnFoucusStatic(tempDatas[tempJ].name_pri);
  350. yZT.gameObject.SetActive(true);
  351. ChangeRightContent(tempJ);
  352. middleContent.gameObject.SetActive(false);
  353. rightContent.gameObject.SetActive(false);
  354. LeftBtnClick(1, false);
  355. });
  356. num++;
  357. }
  358. }
  359. layerBtn.secContent.gameObject.SetActive(true);
  360. }
  361. else {
  362. List<LayerUnitData> tempDatas = new List<LayerUnitData>(GlobalData.layerUnitDatas);
  363. for (int j = 0; j < tempDatas.Count; j++)
  364. {
  365. if ((int)tempDatas[j].type == layerDatas[i].layerID)
  366. {
  367. int tempJ = j;
  368. SecLayerBtn secLayerBtn = Instantiate(secLayerBtnPrefab);
  369. secLayerBtn.SetLayerBtnData(tempDatas[j].name);
  370. secLayerBtn.GetComponent<RectTransform>().SetParent(layerBtn.secContent.GetComponent<RectTransform>());
  371. secLayerBtn.btn.onClick.AddListener(() => {
  372. CameraManager.SwitchCamera(0);
  373. viewMode = ViewMode.normal;
  374. StaticLod.instance.OnFoucusStatic(tempDatas[tempJ].name_pri);
  375. yZT.gameObject.SetActive(true);
  376. ChangeRightContent(tempJ);
  377. middleContent.gameObject.SetActive(false);
  378. rightContent.gameObject.SetActive(false);
  379. LeftBtnClick(1, false);
  380. });
  381. num++;
  382. }
  383. }
  384. }
  385. layerBtn.btn.GetComponent<Button>().onClick.AddListener(() =>
  386. {
  387. for (int j = 0; j < layerBtns.Count; j++)
  388. {
  389. layerBtns[j].SetUseful(false);
  390. layerBtns[j].secContent.gameObject.SetActive(false);
  391. }
  392. layerBtns[index].SetUseful(true);
  393. layerBtns[index].secContent.gameObject.SetActive(true);
  394. //ChangeRuntimeLayer(index);
  395. });
  396. layerBtn.SetLayerBtnData(layerSprite[layerDatas[i].layerID], layerDatas[i].layerName, num.ToString());
  397. layerBtn.GetComponent<RectTransform>().SetParent(content.GetComponent<RectTransform>());
  398. layerBtn.transform.localScale = Vector3.one;
  399. layerBtns.Add(layerBtn);
  400. }
  401. content.GetComponent<VerticalLayoutGroup>().SetLayoutVertical();
  402. layerBtns[0].SetUseful(true);
  403. }
  404. void ChangeRightContent(int index) {
  405. for (int i = 0; i < infoRight.childCount; i++) {
  406. infoRight.GetChild(i).gameObject.SetActive(false);
  407. }
  408. infoRight.GetChild(index).gameObject.SetActive(true);
  409. GameObject title = infoRight.GetChild(index).GetChild(0).GetChild(1).gameObject;
  410. GameObject text1 = infoRight.GetChild(index).GetChild(0).GetChild(2).gameObject;
  411. if (title != null)
  412. {
  413. title.GetComponent<Text>().text = GlobalData.layerUnitDatas[index].name;
  414. }
  415. if (text1 != null)
  416. {
  417. text1.GetComponent<Text>().text = GlobalData.layerUnitDatas[index].text1;
  418. }
  419. if (infoRight.GetChild(index).GetChild(0).childCount > 3)
  420. {
  421. GameObject text2 = infoRight.GetChild(index).GetChild(0).GetChild(3).gameObject;
  422. if (text2 != null)
  423. {
  424. text2.GetComponent<Text>().text = GlobalData.layerUnitDatas[index].text2;
  425. }
  426. }
  427. }
  428. void InitPoint()
  429. {
  430. GameObject shaPan = GameObject.FindGameObjectWithTag("ShaPan");
  431. for (int i = 0; i < GlobalData.hotPointDatas.Count; i++)
  432. {
  433. HotPointData temp = GlobalData.hotPointDatas[i];
  434. Vector3 tempLocalPosition = CoordinateConverter.GeoToUGUISmall(temp.longitude, temp.latitude);
  435. bool have = false;
  436. for (int j = 0; j < runtimePointLib.Count; j++)
  437. {
  438. if (Vector3.Distance(tempLocalPosition, runtimePointLib[j].bingObj.transform.localPosition) < 0.1)
  439. {
  440. if (runtimePointLib[j].layerIDs.Contains((int)temp.type))
  441. {
  442. have = true;
  443. break;
  444. }
  445. else {
  446. have = true;
  447. runtimePointLib[j].Refresh(hotPointSprite[8]);
  448. runtimePointLib[j].layerIDs.Add((int)temp.type);
  449. break;
  450. }
  451. }
  452. }
  453. if (have) {
  454. continue;
  455. }
  456. RuntimePoint newPoint = Instantiate(pointPrefab, Vector3.zero, Quaternion.identity);
  457. int tempI = i;
  458. newPoint.GetComponent<RectTransform>().SetParent(pointParent);
  459. newPoint.InitPoint(hotPointSprite[(int)(temp.type)], temp.name_pri, temp.name);;
  460. newPoint.layerIDs.Add((int)(temp.type));
  461. newPoint.bingObj = Instantiate(runtimePointObj).gameObject;
  462. newPoint.bingObj.transform.SetParent(shaPan.transform.GetChild(6));
  463. newPoint.bingObj.transform.localEulerAngles = Vector3.zero;
  464. newPoint.bingObj.transform.localScale = Vector3.one;
  465. newPoint.bingObj.transform.localPosition = tempLocalPosition;
  466. newPoint.bingObj.name = temp.name;
  467. newPoint.onChildClick += OnChooseNewPointClick;
  468. newPoint.onPointClick = () =>
  469. {
  470. OnChooseNewPointClick(temp, newPoint);
  471. };
  472. runtimePointLib.Add(newPoint);
  473. }
  474. }
  475. void OnChooseNewPointClick(int selectIndex, RuntimePoint newPoint) {
  476. if (selectIndex == 0 || selectIndex == 3 || selectIndex == 5)
  477. {
  478. OnePicNav.instance.OnButtnClick(2);
  479. }
  480. else if (selectIndex == 1 || selectIndex == 2)
  481. {
  482. OnePicNav.instance.SwitchToGlobalWeather();
  483. }
  484. else if (selectIndex == 4)
  485. {
  486. OnePicNav.instance.SwitchToGlobalWaterHeight();
  487. }
  488. else if (selectIndex >= 6)
  489. {
  490. CameraManager.SwitchCamera(0);
  491. viewMode = ViewMode.normal;
  492. StaticLod.instance.OnFoucusStatic(newPoint.staticImp);
  493. yZT.gameObject.SetActive(true);
  494. int index = FindIndexByLayerUnitName(newPoint.bingObj.gameObject.name);
  495. ChangeRightContent(index);
  496. middleContent.gameObject.SetActive(false);
  497. rightContent.gameObject.SetActive(false);
  498. LeftBtnClick(1, false);
  499. }
  500. }
  501. int FindIndexByLayerUnitName(string name) {
  502. for (int i = 0; i < GlobalData.layerUnitDatas.Count; i++) {
  503. if (GlobalData.layerUnitDatas[i].name == name.Trim()) {
  504. return i;
  505. }
  506. }
  507. return -1;
  508. }
  509. void OnChooseNewPointClick(HotPointData temp, RuntimePoint newPoint) {
  510. if (newPoint.layerIDs.Count < 2)
  511. {
  512. OnNewPointClick(temp, newPoint);
  513. }
  514. }
  515. void OnNewPointClick(HotPointData temp, RuntimePoint newPoint)
  516. {
  517. if ((int)temp.type == 0 || (int)temp.type == 3 || (int)temp.type == 5) {
  518. OnePicNav.instance.OnButtnClick(2);
  519. }
  520. else if ((int)temp.type == 1 || (int)temp.type == 2) {
  521. OnePicNav.instance.SwitchToGlobalWeather();
  522. }
  523. else if ((int)temp.type == 4)
  524. {
  525. OnePicNav.instance.SwitchToGlobalWaterHeight();
  526. }
  527. else if ((int)temp.type >= 6)
  528. {
  529. CameraManager.SwitchCamera(0);
  530. viewMode = ViewMode.normal;
  531. StaticLod.instance.OnFoucusStatic(newPoint.staticImp);
  532. yZT.gameObject.SetActive(true);
  533. int index = FindIndexByLayerUnitName(temp.name);
  534. ChangeRightContent(index);
  535. middleContent.gameObject.SetActive(false);
  536. rightContent.gameObject.SetActive(false);
  537. LeftBtnClick(1, false);
  538. }
  539. }
  540. async Task InitData() {
  541. await new WaitUntil(() => {
  542. return GlobalData.layerUnitDatas.Count > 0;
  543. });
  544. }
  545. async Task InitPointData()
  546. {
  547. await new WaitUntil(() =>
  548. {
  549. return GlobalData.hotPointDatas.Count > 0;
  550. });
  551. }
  552. void Init() {
  553. yZT.gameObject.SetActive(false);
  554. middleContent.gameObject.SetActive(true);
  555. rightContent.gameObject.SetActive(true);
  556. LeftBtnClick(currentActiveLeft);
  557. }
  558. void InitReturnBtn() {
  559. returnBtn.onClick.AddListener(() =>
  560. {
  561. CameraManager.SwitchCamera(1);
  562. viewMode = ViewMode.miniMap;
  563. Init();
  564. });
  565. }
  566. void ChangeRuntimeLayer(int layer,bool show) {
  567. if (show)
  568. {
  569. if (cancelLayer.Contains(layer))
  570. {
  571. cancelLayer.Remove(layer);
  572. }
  573. }
  574. else {
  575. if (!cancelLayer.Contains(layer))
  576. {
  577. cancelLayer.Add(layer);
  578. }
  579. }
  580. for (int i = 0; i < runtimePointLib.Count; i++) {
  581. if (runtimePointLib[i].layerIDs.Contains(layer)) {
  582. if (runtimePointLib[i].layerIDs.Count < 2)
  583. {
  584. runtimePointLib[i].gameObject.SetActive(show);
  585. }
  586. else {
  587. List<int> tempLayers = new List<int>(runtimePointLib[i].layerIDs);
  588. for (int j = 0; j < cancelLayer.Count; j++) {
  589. if (tempLayers.Contains(cancelLayer[j])) {
  590. tempLayers.Remove(cancelLayer[j]);
  591. }
  592. }
  593. if (tempLayers.Count < 1)
  594. {
  595. runtimePointLib[i].gameObject.SetActive(false);
  596. }
  597. else {
  598. runtimePointLib[i].gameObject.SetActive(true);
  599. }
  600. }
  601. }
  602. }
  603. }
  604. void ShootRay()
  605. {
  606. Ray ray = CameraManager.instance.mainCamera.ScreenPointToRay(Input.mousePosition);
  607. RaycastHit hit;
  608. if (Physics.Raycast(ray, out hit,20000,1<<8|1<<9))
  609. {
  610. CameraBird bird = CameraManager.instance.mainCamera.GetComponent<CameraBird>();
  611. if (hit.collider.gameObject.layer == LayerMask.NameToLayer("EarthTile"))
  612. {
  613. if(bird.transform.position.y > 1000)
  614. {
  615. bird.SetCameraToCenterFade(hit.point, 1100);
  616. }
  617. }
  618. else if(hit.collider.gameObject.layer == LayerMask.NameToLayer("StaticImportant"))
  619. {
  620. StaticImportant si = hit.collider.gameObject.GetComponent<StaticImportant>();
  621. int index = StaticLod.instance.OnFoucusStatic(si);
  622. yZT.gameObject.SetActive(true);
  623. ChangeRightContent(index);
  624. middleContent.gameObject.SetActive(false);
  625. rightContent.gameObject.SetActive(false);
  626. LeftBtnClick(1,false);
  627. }
  628. }
  629. else
  630. {
  631. Debug.Log("No hit");
  632. }
  633. }
  634. private void Update()
  635. {
  636. if (Input.GetMouseButtonDown(0)) // 检测鼠标左键点击
  637. {
  638. clickInterval = 0.0f;
  639. startClickPosition = Input.mousePosition;
  640. }
  641. clickInterval += Time.deltaTime;
  642. if (Input.GetMouseButtonUp(0)) {
  643. if (clickInterval < 0.2f && Vector3.Distance(startClickPosition,Input.mousePosition) < 10f) {
  644. if (!CameraManager.instance.secondCamera.enabled)
  645. {
  646. ShootRay();
  647. }
  648. }
  649. }
  650. }
  651. }