XHGKLayer.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434
  1. using DG.Tweening;
  2. using Newtonsoft.Json;
  3. using Newtonsoft.Json.Linq;
  4. using System;
  5. using System.Collections;
  6. using System.Collections.Generic;
  7. using System.Threading.Tasks;
  8. using UnityAsync;
  9. using UnityEditor;
  10. using UnityEngine;
  11. using UnityEngine.Networking;
  12. using UnityEngine.UI;
  13. using WaitUntil = UnityAsync.WaitUntil;
  14. public enum XHGKImportantStatic
  15. {
  16. BY,
  17. TK,
  18. GTK,
  19. YK
  20. }
  21. [System.Serializable]
  22. public class DSJData
  23. {
  24. public string year;
  25. public string date;
  26. public string title;
  27. public string pos;
  28. public string content;
  29. public DSJData(string y, string d, string t, string p, string c)
  30. {
  31. year = y;
  32. date = d;
  33. title = t;
  34. pos = p;
  35. content = c;
  36. }
  37. }
  38. [System.Serializable]
  39. public class XHGKLayerData
  40. {
  41. public string datatime;
  42. public string title;
  43. public XHGKImportantStatic importantStatic;
  44. public int year;
  45. public bool havePic;
  46. public string content;
  47. }
  48. public class XHGKLayer : YZTRootLayer
  49. {
  50. public RectTransform xhgkContent;
  51. public RectTransform compare;
  52. public RectTransform yearContent;
  53. public RectTransform middleContent;
  54. public RectTransform importantContent;
  55. public RectTransform rightContent;
  56. public ScrollRect scrollView;
  57. public List<XHGKLayerData> xHGKLayerDatas16;
  58. public List<XHGKLayerData> xHGKLayerDatas17;
  59. public List<XHGKLayerData> xHGKLayerDatas18;
  60. public List<XHGKLayerData> xHGKLayerDatas19;
  61. public List<XHGKLayerData> xHGKLayerDatas20;
  62. public List<XHGKLayerData> xHGKLayerDatas21;
  63. public List<XHGKLayerData> xHGKLayerDatas22;
  64. public int currentActive = 0;
  65. public List<YearBtn> yearBtns;
  66. public ImportBtn importThingPrefab;
  67. public Button closeBtn;
  68. public Button showInfoBtn;
  69. public Sprite[] showSprites;
  70. public List<ImportBtn> importBtns;
  71. public Image leftImage;
  72. public RawImage rightImage;
  73. public Image beforeImage;
  74. public RawImage afterImage;
  75. public Sprite[] workImages;
  76. public Text compareText;
  77. public Button compareBtn;
  78. public Button exitCompareBtn;
  79. public Transform filterContent;
  80. private string[] filterName = new string[5] { "", "补元闸", "套口闸", "腰口泵站", "高潭口二站" };
  81. // Start is called before the first frame update
  82. async void Awake()
  83. {
  84. for (int i = 0; i < filterContent.childCount; i++)
  85. {
  86. Button btn = filterContent.GetChild(i).GetComponent<Button>();
  87. int temp = i;
  88. btn.onClick.AddListener(() =>
  89. {
  90. InitDSJ(filterName[temp]);
  91. });
  92. }
  93. yearBtns = new List<YearBtn>();
  94. for (int i = 0; i < yearContent.childCount; i++)
  95. {
  96. yearBtns.Add(yearContent.GetChild(i).GetComponent<YearBtn>());
  97. int temp = i;
  98. if (yearBtns[i].defaultActive)
  99. {
  100. currentActive = temp;
  101. }
  102. yearBtns[temp].heightY = -320 + 56 * temp;
  103. yearBtns[temp].GetComponent<UnityEngine.UI.Button>().onClick.AddListener(() =>
  104. {
  105. yearContent.DOLocalMoveY(yearBtns[temp].heightY, 0.3f);
  106. for (int j = 0; j < yearBtns.Count; j++)
  107. {
  108. yearBtns[j].OnActive(false);
  109. }
  110. currentActive = temp;
  111. yearBtns[temp].OnActive(true);
  112. ChangeImportantToCurrent();
  113. });
  114. }
  115. compareBtn.onClick.AddListener(() =>
  116. {
  117. xhgkContent.gameObject.SetActive(false);
  118. compare.gameObject.SetActive(true);
  119. });
  120. exitCompareBtn.onClick.AddListener(() =>
  121. {
  122. xhgkContent.gameObject.SetActive(true);
  123. compare.gameObject.SetActive(false);
  124. });
  125. await InitData();
  126. InitDSJ();
  127. }
  128. async Task InitData()
  129. {
  130. await new WaitUntil(() =>
  131. {
  132. return GlobalData.dsjContents.Count > 0;
  133. });
  134. }
  135. void InitDSJ(string filter = "")
  136. {
  137. xHGKLayerDatas16.Clear();
  138. xHGKLayerDatas17.Clear();
  139. xHGKLayerDatas18.Clear();
  140. xHGKLayerDatas19.Clear();
  141. xHGKLayerDatas20.Clear();
  142. xHGKLayerDatas21.Clear();
  143. xHGKLayerDatas22.Clear();
  144. for (int i = 0; i < GlobalData.dsjContents.Count; i++)
  145. {
  146. XHGKLayerData xHGKLayerDatas = new XHGKLayerData();
  147. xHGKLayerDatas.year = int.Parse(GlobalData.dsjContents[i].year);
  148. xHGKLayerDatas.datatime = GlobalData.dsjContents[i].date;
  149. xHGKLayerDatas.title = GlobalData.dsjContents[i].title;
  150. if (filter != "" && filter != GlobalData.dsjContents[i].pos)
  151. {
  152. continue;
  153. }
  154. switch (GlobalData.dsjContents[i].pos)
  155. {
  156. case "补元闸":
  157. xHGKLayerDatas.importantStatic = XHGKImportantStatic.BY;
  158. break;
  159. case "套口闸":
  160. xHGKLayerDatas.importantStatic = XHGKImportantStatic.TK;
  161. break;
  162. case "高潭口二站":
  163. xHGKLayerDatas.importantStatic = XHGKImportantStatic.GTK;
  164. break;
  165. case "腰口泵站":
  166. xHGKLayerDatas.importantStatic = XHGKImportantStatic.YK;
  167. break;
  168. default:
  169. xHGKLayerDatas.importantStatic = XHGKImportantStatic.BY;
  170. break;
  171. }
  172. //xHGKLayerDatas.importantStatic = XHGKImportantStatic.BY;
  173. xHGKLayerDatas.content = GlobalData.dsjContents[i].content;
  174. xHGKLayerDatas.havePic = true;
  175. switch (GlobalData.dsjContents[i].year)
  176. {
  177. case "2016":
  178. xHGKLayerDatas.havePic = false;
  179. xHGKLayerDatas16.Add(xHGKLayerDatas);
  180. break;
  181. case "2017":
  182. xHGKLayerDatas17.Add(xHGKLayerDatas);
  183. break;
  184. case "2018":
  185. xHGKLayerDatas18.Add(xHGKLayerDatas);
  186. break;
  187. case "2019":
  188. xHGKLayerDatas19.Add(xHGKLayerDatas);
  189. break;
  190. case "2020":
  191. xHGKLayerDatas20.Add(xHGKLayerDatas);
  192. break;
  193. case "2021":
  194. xHGKLayerDatas21.Add(xHGKLayerDatas);
  195. break;
  196. case "2022":
  197. xHGKLayerDatas22.Add(xHGKLayerDatas);
  198. break;
  199. }
  200. }
  201. ChangeImportantToCurrent();
  202. RefreshToFirst();
  203. }
  204. private void OnEnable()
  205. {
  206. RefreshToFirst();
  207. }
  208. async void RefreshRightImage(int year, int index)
  209. {
  210. string picName = "";
  211. switch (index)
  212. {
  213. case 0:
  214. picName = "by.jpg";
  215. break;
  216. case 1:
  217. picName = "tk.jpg";
  218. break;
  219. case 2:
  220. picName = "gtk.jpg";
  221. break;
  222. case 3:
  223. picName = "yk.jpg";
  224. break;
  225. }
  226. picName = ServerAddress.ServerPicPath + year + "/" + picName;
  227. Debug.Log(picName);
  228. WWW www = new WWW(picName);
  229. await new UnityAsync.WaitUntil(() =>
  230. {
  231. return www.isDone;
  232. });
  233. rightImage.texture = www.texture;
  234. afterImage.texture = www.texture;
  235. www.Dispose();
  236. Resources.UnloadUnusedAssets();
  237. }
  238. void RefreshToFirst()
  239. {
  240. if (importBtns.Count < 1) return;
  241. for (int i = 0; i < importBtns.Count; i++)
  242. {
  243. importBtns[i].OnActive(false);
  244. }
  245. importBtns[0].OnActive(true);
  246. int staticIndex = (int)importBtns[0].data1.importantStatic;
  247. StaticLod.instance.OnFoucusStatic(staticIndex);
  248. for (int j = 0; j < rightContent.childCount; j++) rightContent.GetChild(j).gameObject.SetActive(false);
  249. rightContent.GetChild(staticIndex).gameObject.SetActive(true);
  250. leftImage.sprite = workImages[staticIndex];
  251. beforeImage.sprite = workImages[staticIndex];
  252. RefreshRightImage(importBtns[staticIndex].data1.year, staticIndex);
  253. compareText.text = importBtns[staticIndex].data1.content;
  254. }
  255. void ChangeImportantToCurrent()
  256. {
  257. switch (currentActive)
  258. {
  259. case 0:
  260. InitDSJPanel(xHGKLayerDatas16);
  261. break;
  262. case 1:
  263. InitDSJPanel(xHGKLayerDatas17);
  264. break;
  265. case 2:
  266. InitDSJPanel(xHGKLayerDatas18);
  267. break;
  268. case 3:
  269. InitDSJPanel(xHGKLayerDatas19);
  270. break;
  271. case 4:
  272. InitDSJPanel(xHGKLayerDatas20);
  273. break;
  274. case 5:
  275. InitDSJPanel(xHGKLayerDatas21);
  276. break;
  277. case 6:
  278. InitDSJPanel(xHGKLayerDatas22);
  279. break;
  280. }
  281. }
  282. async Task InitDSJPanel(List<XHGKLayerData> xHGKLayerDatas)
  283. {
  284. if (middleContent.gameObject.activeSelf)
  285. {
  286. showInfoBtn.gameObject.SetActive(false);
  287. }
  288. closeBtn.onClick.AddListener(() =>
  289. {
  290. showInfoBtn.gameObject.SetActive(true);
  291. middleContent.gameObject.SetActive(false);
  292. });
  293. showInfoBtn.onClick.AddListener(() =>
  294. {
  295. showInfoBtn.gameObject.SetActive(false);
  296. middleContent.gameObject.SetActive(true);
  297. });
  298. scrollView.GetComponent<CanvasGroup>().alpha = 0;
  299. for (int i = importBtns.Count - 1; i >= 0; i--)
  300. {
  301. Destroy(importBtns[i].gameObject);
  302. importBtns.RemoveAt(i);
  303. }
  304. for (int i = 0; i < xHGKLayerDatas.Count; i++)
  305. {
  306. ImportBtn btn = Instantiate(importThingPrefab);
  307. btn.GetComponent<RectTransform>().SetParent(importantContent);
  308. btn.GetComponent<RectTransform>().localScale = Vector3.one;
  309. int tempI = i;
  310. btn.OnInit(xHGKLayerDatas[tempI]);
  311. btn.OnActive(false);
  312. btn.button.onClick.AddListener(() =>
  313. {
  314. for (int i = 0; i < importBtns.Count; i++)
  315. {
  316. importBtns[i].OnActive(false);
  317. }
  318. importBtns[tempI].OnActive(true);
  319. int staticIndex = (int)importBtns[tempI].data1.importantStatic;
  320. StaticLod.instance.OnFoucusStatic(staticIndex);
  321. for (int j = 0; j < rightContent.childCount; j++) rightContent.GetChild(j).gameObject.SetActive(false);
  322. rightContent.GetChild(staticIndex).gameObject.SetActive(true);
  323. leftImage.sprite = workImages[staticIndex];
  324. beforeImage.sprite = workImages[staticIndex];
  325. RefreshRightImage(importBtns[tempI].data1.year, staticIndex);
  326. compareText.text = importBtns[tempI].data1.content;
  327. });
  328. importBtns.Add(btn);
  329. }
  330. await new UnityAsync.WaitForSeconds(0.04f);
  331. scrollView.verticalNormalizedPosition = 1;
  332. DOTween.To(() => scrollView.GetComponent<CanvasGroup>().alpha, x => scrollView.GetComponent<CanvasGroup>().alpha = x, 1, 0.5f);
  333. }
  334. // Update is called once per frame
  335. void Update()
  336. {
  337. if (yearBtns.Count > 0)
  338. {
  339. for (int i = 0; i < yearBtns.Count; i++)
  340. {
  341. int offset = Mathf.Abs(i - currentActive);
  342. yearBtns[i].normalDig.color = new Color(1, 1, 1, 1 - 0.2f * offset);
  343. yearBtns[i].activeDig.color = new Color(1, 1, 1, 1 - 0.2f * offset);
  344. }
  345. }
  346. if (StaticLod.instance.currentStatic != null)
  347. {
  348. if (middleContent.gameObject.activeSelf)
  349. {
  350. Vector3 pos = CameraManager.instance.mainCamera.WorldToScreenPoint(StaticLod.instance.currentStatic.transform.position) * 1920.0f / Screen.width;
  351. middleContent.anchoredPosition = new Vector3(pos.x - 400, pos.y + 200, pos.z);
  352. if (middleContent.anchoredPosition.x < 500 || middleContent.anchoredPosition.x > 1400 || middleContent.anchoredPosition.y < 70 || middleContent.anchoredPosition.y > 950)
  353. {
  354. if (middleContent.GetComponent<CanvasGroup>().alpha > 0)
  355. {
  356. middleContent.GetComponent<CanvasGroup>().alpha -= Time.deltaTime * 3;
  357. }
  358. }
  359. else
  360. {
  361. if (middleContent.GetComponent<CanvasGroup>().alpha < 1)
  362. {
  363. middleContent.GetComponent<CanvasGroup>().alpha += Time.deltaTime * 3;
  364. }
  365. }
  366. }
  367. }
  368. }
  369. private void LateUpdate()
  370. {
  371. showInfoBtn.GetComponent<RectTransform>().anchoredPosition = CameraManager.instance.mainCamera.WorldToScreenPoint(StaticLod.instance.currentStatic.transform.position) / Screen.width * 1920.0f;
  372. }
  373. }