YZTLayer.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  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. }
  39. public class YZTLayer : YZTRootLayer
  40. {
  41. public VerticalLayoutGroup content;
  42. public Sprite[] layerSprite;
  43. public LayerBtn layerBtnPrefab;
  44. public SecLayerBtn secLayerBtnPrefab;
  45. public YZTLayerData[] layerDatas;
  46. public RectTransform leftContent;
  47. public RectTransform leftContentView;
  48. List<LayerBtn> layerBtns = new List<LayerBtn>();
  49. public RuntimePoint pointPrefab;
  50. public GameObject runtimePointObj;
  51. public RectTransform pointParent;
  52. List<RuntimePoint> runtimePointLib = new List<RuntimePoint>();
  53. public GameObject yZTMini;
  54. public GameObject yZT;
  55. public RectTransform rightContent;
  56. public Button returnBtn;
  57. private float clickInterval;
  58. private Vector3 startClickPosition;
  59. // Start is called before the first frame update
  60. async void Awake()
  61. {
  62. viewMode = ViewMode.miniMap;
  63. await InitData();
  64. Init();
  65. InitLayerBtns();
  66. InitPoint();
  67. InitReturnBtn();
  68. }
  69. void InitLayerBtns()
  70. {
  71. layerBtns = new List<LayerBtn>();
  72. for (int i = 0; i < layerDatas.Length; i++)
  73. {
  74. LayerBtn layerBtn = Instantiate(layerBtnPrefab);
  75. layerBtn.SetUseful(false);
  76. int index = i;
  77. int num = 0;
  78. if (i == 0)
  79. {
  80. List<LayerUnitData> tempDatas = new List<LayerUnitData>(GlobalData.layerUnitDatas);
  81. for (int j = 0; j < tempDatas.Count; j++)
  82. {
  83. if (tempDatas[j].special)
  84. {
  85. int tempJ = j;
  86. SecLayerBtn secLayerBtn = Instantiate(secLayerBtnPrefab);
  87. secLayerBtn.SetLayerBtnData(tempDatas[j].name);
  88. secLayerBtn.GetComponent<RectTransform>().SetParent(layerBtn.secContent.GetComponent<RectTransform>());
  89. secLayerBtn.btn.onClick.AddListener(() => {
  90. CameraManager.SwitchCamera(0);
  91. viewMode = ViewMode.normal;
  92. StaticLod.instance.OnFoucusStatic(tempDatas[tempJ].name_pri);
  93. yZT.gameObject.SetActive(true);
  94. ChangeRightContent(tempJ);
  95. yZTMini.gameObject.SetActive(false);
  96. });
  97. num++;
  98. }
  99. }
  100. layerBtn.secContent.gameObject.SetActive(true);
  101. }
  102. else {
  103. List<LayerUnitData> tempDatas = new List<LayerUnitData>(GlobalData.layerUnitDatas);
  104. for (int j = 0; j < tempDatas.Count; j++)
  105. {
  106. if ((int)tempDatas[j].type == layerDatas[i].layerID)
  107. {
  108. int tempJ = j;
  109. SecLayerBtn secLayerBtn = Instantiate(secLayerBtnPrefab);
  110. secLayerBtn.SetLayerBtnData(tempDatas[j].name);
  111. secLayerBtn.GetComponent<RectTransform>().SetParent(layerBtn.secContent.GetComponent<RectTransform>());
  112. secLayerBtn.btn.onClick.AddListener(() => {
  113. CameraManager.SwitchCamera(0);
  114. viewMode = ViewMode.normal;
  115. StaticLod.instance.OnFoucusStatic(tempDatas[tempJ].name_pri);
  116. yZT.gameObject.SetActive(true);
  117. ChangeRightContent(tempJ);
  118. yZTMini.gameObject.SetActive(false);
  119. });
  120. num++;
  121. }
  122. }
  123. }
  124. layerBtn.btn.GetComponent<Button>().onClick.AddListener(() =>
  125. {
  126. for (int j = 0; j < layerBtns.Count; j++)
  127. {
  128. layerBtns[j].SetUseful(false);
  129. layerBtns[j].secContent.gameObject.SetActive(false);
  130. }
  131. layerBtns[index].SetUseful(true);
  132. layerBtns[index].secContent.gameObject.SetActive(true);
  133. ChangeRuntimeLayer(index);
  134. });
  135. layerBtn.SetLayerBtnData(layerSprite[layerDatas[i].layerID], layerDatas[i].layerName, num.ToString());
  136. layerBtn.GetComponent<RectTransform>().SetParent(content.GetComponent<RectTransform>());
  137. layerBtn.transform.localScale = Vector3.one;
  138. layerBtns.Add(layerBtn);
  139. }
  140. content.GetComponent<VerticalLayoutGroup>().SetLayoutVertical();
  141. layerBtns[0].SetUseful(true);
  142. }
  143. void ChangeRightContent(int index) {
  144. for (int i = 0; i < rightContent.childCount; i++) {
  145. rightContent.GetChild(i).gameObject.SetActive(false);
  146. }
  147. leftContent.sizeDelta = new Vector2(leftContent.sizeDelta.x, 914f);
  148. leftContentView.sizeDelta = new Vector2(leftContentView.sizeDelta.x, 839f);
  149. rightContent.GetChild(index).gameObject.SetActive(true);
  150. GameObject title = rightContent.GetChild(index).GetChild(0).GetChild(1).gameObject;
  151. GameObject text1 = rightContent.GetChild(index).GetChild(0).GetChild(2).gameObject;
  152. if (title != null)
  153. {
  154. title.GetComponent<Text>().text = GlobalData.layerUnitDatas[index].name;
  155. }
  156. if (text1 != null)
  157. {
  158. text1.GetComponent<Text>().text = GlobalData.layerUnitDatas[index].text1;
  159. }
  160. if (rightContent.GetChild(index).GetChild(0).childCount > 3)
  161. {
  162. GameObject text2 = rightContent.GetChild(index).GetChild(0).GetChild(3).gameObject;
  163. if (text2 != null)
  164. {
  165. text2.GetComponent<Text>().text = GlobalData.layerUnitDatas[index].text2;
  166. }
  167. }
  168. }
  169. void InitPoint()
  170. {
  171. GameObject shaPan = GameObject.FindGameObjectWithTag("ShaPan");
  172. for (int i = 0; i < GlobalData.layerUnitDatas.Count; i++)
  173. {
  174. LayerUnitData temp = GlobalData.layerUnitDatas[i];
  175. RuntimePoint newPoint = Instantiate(pointPrefab, Vector3.zero, Quaternion.identity);
  176. if (temp.special) {
  177. newPoint.layerIDs.Add(0);
  178. newPoint.gameObject.SetActive(true);
  179. newPoint.transform.localScale = Vector3.one * 0.8f;
  180. }
  181. else
  182. {
  183. newPoint.gameObject.SetActive(false);
  184. newPoint.transform.localScale = Vector3.one * 0.4f;
  185. }
  186. int tempI = i;
  187. newPoint.GetComponent<RectTransform>().SetParent(pointParent);
  188. newPoint.InitPoint(layerSprite[(int)(temp.type)], temp.name_pri, temp.name);;
  189. newPoint.layerIDs.Add((int)(temp.type));
  190. newPoint.bingObj = Instantiate(runtimePointObj).gameObject;
  191. newPoint.bingObj.transform.SetParent(shaPan.transform);
  192. newPoint.bingObj.transform.localEulerAngles = Vector3.zero;
  193. newPoint.bingObj.transform.localScale = Vector3.one;
  194. newPoint.bingObj.transform.localPosition = CoordinateConverter.GeoToUGUISmall(temp.longitude, temp.latitude);
  195. newPoint.bingObj.name = temp.name;
  196. newPoint.btn.onClick.AddListener(() =>
  197. {
  198. CameraManager.SwitchCamera(0);
  199. viewMode = ViewMode.normal;
  200. StaticLod.instance.OnFoucusStatic(newPoint.staticImp);
  201. yZT.gameObject.SetActive(true);
  202. ChangeRightContent(tempI);
  203. yZTMini.gameObject.SetActive(false);
  204. });
  205. runtimePointLib.Add(newPoint);
  206. }
  207. }
  208. async Task InitData() {
  209. await new WaitUntil(() => {
  210. return GlobalData.layerUnitDatas.Count > 0;
  211. });
  212. }
  213. void Init() {
  214. leftContent.sizeDelta = new Vector2(leftContent.sizeDelta.x, 604.1545f);
  215. leftContentView.sizeDelta = new Vector2(leftContentView.sizeDelta.x, 526.1387f);
  216. yZT.gameObject.SetActive(false);
  217. yZTMini.gameObject.SetActive(true);
  218. }
  219. void InitReturnBtn() {
  220. returnBtn.onClick.AddListener(() =>
  221. {
  222. CameraManager.SwitchCamera(1);
  223. viewMode = ViewMode.miniMap;
  224. Init();
  225. });
  226. }
  227. void ChangeRuntimeLayer(int layer) {
  228. for (int i = 0; i < runtimePointLib.Count; i++) {
  229. runtimePointLib[i].gameObject.SetActive(false);
  230. if (runtimePointLib[i].layerIDs.Contains(layer)) {
  231. runtimePointLib[i].gameObject.SetActive(true);
  232. }
  233. }
  234. }
  235. void ShootRay()
  236. {
  237. Ray ray = CameraManager.instance.mainCamera.ScreenPointToRay(Input.mousePosition);
  238. RaycastHit hit;
  239. if (Physics.Raycast(ray, out hit,20000,1<<8|1<<9))
  240. {
  241. CameraBird bird = CameraManager.instance.mainCamera.GetComponent<CameraBird>();
  242. if (hit.collider.gameObject.layer == LayerMask.NameToLayer("EarthTile"))
  243. {
  244. if(bird.transform.position.y > 1000)
  245. {
  246. bird.SetCameraToCenterFade(hit.point, 1100);
  247. }
  248. }
  249. else if(hit.collider.gameObject.layer == LayerMask.NameToLayer("StaticImportant"))
  250. {
  251. StaticImportant si = hit.collider.gameObject.GetComponent<StaticImportant>();
  252. int index = StaticLod.instance.OnFoucusStatic(si);
  253. yZT.gameObject.SetActive(true);
  254. ChangeRightContent(index);
  255. yZTMini.gameObject.SetActive(false);
  256. }
  257. }
  258. else
  259. {
  260. Debug.Log("No hit");
  261. }
  262. }
  263. private void Update()
  264. {
  265. if (Input.GetMouseButtonDown(0)) // 检测鼠标左键点击
  266. {
  267. clickInterval = 0.0f;
  268. startClickPosition = Input.mousePosition;
  269. }
  270. clickInterval += Time.deltaTime;
  271. if (Input.GetMouseButtonUp(0)) {
  272. if (clickInterval < 0.2f && Vector3.Distance(startClickPosition,Input.mousePosition) < 10f) {
  273. if (!yZTMini.gameObject.activeSelf)
  274. {
  275. ShootRay();
  276. }
  277. }
  278. }
  279. }
  280. }