XHGKLayer.cs 12 KB

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