XHGKLayer.cs 14 KB

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