XHGKLayer.cs 14 KB

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