using DG.Tweening; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using System; using System.Collections; using System.Collections.Generic; using System.Threading.Tasks; using UnityAsync; using UnityEditor; using UnityEngine; using UnityEngine.Networking; using UnityEngine.UI; using WaitUntil = UnityAsync.WaitUntil; public enum XHGKImportantStatic { BY, TK, GTK, YK } [System.Serializable] public class DSJData { public string year; public string date; public string title; public string pos; public string content; public DSJData(string y,string d,string t,string p,string c) { year = y; date = d; title = t; pos = p; content = c; } } [System.Serializable] public class XHGKLayerData { public string datatime; public string title; public XHGKImportantStatic importantStatic; public int year; public bool havePic; public string content; } public class XHGKLayer : YZTRootLayer { public RectTransform xhgkContent; public RectTransform compare; public RectTransform yearContent; public RectTransform middleContent; public RectTransform importantContent; public RectTransform rightContent; public ScrollRect scrollView; public List xHGKLayerDatas16; public List xHGKLayerDatas17; public List xHGKLayerDatas18; public List xHGKLayerDatas19; public List xHGKLayerDatas20; public List xHGKLayerDatas21; public List xHGKLayerDatas22; public int currentActive = 0; public List yearBtns; public ImportBtn importThingPrefab; public Button closeBtn; public Button showInfoBtn; public Sprite[] showSprites; public List importBtns; public Image leftImage; public RawImage rightImage; public Image beforeImage; public RawImage afterImage; public Sprite[] workImages; public Text compareText; public Button compareBtn; public Button exitCompareBtn; // Start is called before the first frame update async void Awake() { yearBtns = new List(); for (int i = 0; i < yearContent.childCount; i++) { yearBtns.Add(yearContent.GetChild(i).GetComponent()); int temp = i; if (yearBtns[i].defaultActive) { currentActive = temp; } yearBtns[temp].heightY = -224 + 56 * temp; yearBtns[temp].GetComponent().onClick.AddListener(() => { yearContent.DOLocalMoveY(yearBtns[temp].heightY, 0.3f); for (int j = 0; j < yearBtns.Count; j++) { yearBtns[j].OnActive(false); } currentActive = temp; yearBtns[temp].OnActive(true); ChangeImportantToCurrent(); }); } compareBtn.onClick.AddListener(() => { xhgkContent.gameObject.SetActive(false); compare.gameObject.SetActive(true); }); exitCompareBtn.onClick.AddListener(() => { xhgkContent.gameObject.SetActive(true); compare.gameObject.SetActive(false); }); await InitData(); InitDSJ(); } async Task InitData() { await new WaitUntil(() => { return GlobalData.dsjContents.Count > 0; }); } void InitDSJ() { for (int i = 0; i < GlobalData.dsjContents.Count; i++) { XHGKLayerData xHGKLayerDatas = new XHGKLayerData(); xHGKLayerDatas.year = int.Parse(GlobalData.dsjContents[i].year); xHGKLayerDatas.datatime = GlobalData.dsjContents[i].date; xHGKLayerDatas.title = GlobalData.dsjContents[i].title; Debug.Log(GlobalData.dsjContents[i].pos); switch (GlobalData.dsjContents[i].pos) { case "补元闸": xHGKLayerDatas.importantStatic = XHGKImportantStatic.BY; break; case "套口闸": xHGKLayerDatas.importantStatic = XHGKImportantStatic.TK; break; case "高潭口二站": xHGKLayerDatas.importantStatic = XHGKImportantStatic.GTK; break; case "腰口泵站": xHGKLayerDatas.importantStatic = XHGKImportantStatic.YK; break; default: xHGKLayerDatas.importantStatic = XHGKImportantStatic.BY; break; } //xHGKLayerDatas.importantStatic = XHGKImportantStatic.BY; xHGKLayerDatas.content = GlobalData.dsjContents[i].content; xHGKLayerDatas.havePic = true; switch (GlobalData.dsjContents[i].year) { case "2016": xHGKLayerDatas.havePic = false; xHGKLayerDatas16.Add(xHGKLayerDatas); break; case "2017": xHGKLayerDatas17.Add(xHGKLayerDatas); break; case "2018": xHGKLayerDatas18.Add(xHGKLayerDatas); break; case "2019": xHGKLayerDatas19.Add(xHGKLayerDatas); break; case "2020": xHGKLayerDatas20.Add(xHGKLayerDatas); break; case "2021": xHGKLayerDatas21.Add(xHGKLayerDatas); break; case "2022": xHGKLayerDatas22.Add(xHGKLayerDatas); break; } } ChangeImportantToCurrent(); RefreshToFirst(); } private void OnEnable() { RefreshToFirst(); } async void RefreshRightImage(int year, int index) { string picName = ""; switch (index) { case 0: picName = "by.jpg"; break; case 1: picName = "tk.jpg"; break; case 2: picName = "gtk.jpg"; break; case 3: picName = "yk.jpg"; break; } picName = ServerAddress.ServerPicPath + year + "/" + picName; Debug.Log(picName); WWW www = new WWW(picName); await new UnityAsync.WaitUntil(() => { return www.isDone; }); rightImage.texture = www.texture; afterImage.texture = www.texture; www.Dispose(); Resources.UnloadUnusedAssets(); } void RefreshToFirst() { if (importBtns.Count < 1) return; for (int i = 0; i < importBtns.Count; i++) { importBtns[i].OnActive(false); } importBtns[0].OnActive(true); int staticIndex = (int)importBtns[0].data1.importantStatic; StaticLod.instance.OnFoucusStatic(staticIndex); for (int j = 0; j < rightContent.childCount; j++) rightContent.GetChild(j).gameObject.SetActive(false); rightContent.GetChild(staticIndex).gameObject.SetActive(true); leftImage.sprite = workImages[staticIndex]; beforeImage.sprite = workImages[staticIndex]; RefreshRightImage(importBtns[staticIndex].data1.year,staticIndex); compareText.text = importBtns[staticIndex].data1.content; } void ChangeImportantToCurrent() { switch (currentActive) { case 0: InitDSJPanel(xHGKLayerDatas16); break; case 1: InitDSJPanel(xHGKLayerDatas17); break; case 2: InitDSJPanel(xHGKLayerDatas18); break; case 3: InitDSJPanel(xHGKLayerDatas19); break; case 4: InitDSJPanel(xHGKLayerDatas20); break; case 5: InitDSJPanel(xHGKLayerDatas21); break; case 6: InitDSJPanel(xHGKLayerDatas22); break; } } async Task InitDSJPanel(List xHGKLayerDatas) { if (middleContent.gameObject.activeSelf) { showInfoBtn.gameObject.SetActive(false); } closeBtn.onClick.AddListener(() => { showInfoBtn.gameObject.SetActive(true); middleContent.gameObject.SetActive(false); }); showInfoBtn.onClick.AddListener(() => { showInfoBtn.gameObject.SetActive(false); middleContent.gameObject.SetActive(true); }); scrollView.GetComponent().alpha = 0; for (int i = importBtns.Count - 1; i >= 0; i--) { Destroy(importBtns[i].gameObject); importBtns.RemoveAt(i); } for (int i = 0; i < xHGKLayerDatas.Count; i++) { ImportBtn btn = Instantiate(importThingPrefab); btn.GetComponent().SetParent(importantContent); btn.GetComponent().localScale = Vector3.one; int tempI = i; btn.OnInit(xHGKLayerDatas[tempI]); btn.OnActive(false); btn.button.onClick.AddListener(() => { for (int i = 0; i < importBtns.Count; i++) { importBtns[i].OnActive(false); } importBtns[tempI].OnActive(true); int staticIndex = (int)importBtns[tempI].data1.importantStatic; StaticLod.instance.OnFoucusStatic(staticIndex); for (int j = 0; j < rightContent.childCount; j++) rightContent.GetChild(j).gameObject.SetActive(false); rightContent.GetChild(staticIndex).gameObject.SetActive(true); leftImage.sprite = workImages[staticIndex]; beforeImage.sprite = workImages[staticIndex]; RefreshRightImage(importBtns[tempI].data1.year,staticIndex); compareText.text = importBtns[tempI].data1.content; }); importBtns.Add(btn); } await new UnityAsync.WaitForSeconds(0.04f); scrollView.verticalNormalizedPosition = 1; DOTween.To(() => scrollView.GetComponent().alpha, x => scrollView.GetComponent().alpha = x, 1, 0.5f); } // Update is called once per frame void Update() { if (yearBtns.Count > 0) { for (int i = 0; i < yearBtns.Count; i++) { int offset = Mathf.Abs(i - currentActive); yearBtns[i].normalDig.color = new Color(1, 1, 1, 1 - 0.2f * offset); yearBtns[i].activeDig.color = new Color(1, 1, 1, 1 - 0.2f * offset); } } if (StaticLod.instance.currentStatic != null) { if (middleContent.gameObject.activeSelf) { Vector3 pos = CameraManager.instance.mainCamera.WorldToScreenPoint(StaticLod.instance.currentStatic.transform.position) * 1920.0f / Screen.width; middleContent.anchoredPosition = new Vector3(pos.x - 400,pos.y + 200, pos.z) ; if (middleContent.anchoredPosition.x < 150 || middleContent.anchoredPosition.x > 1500 || middleContent.anchoredPosition.y < 70 || middleContent.anchoredPosition.y > 950) { if (middleContent.GetComponent().alpha > 0) { middleContent.GetComponent().alpha -= Time.deltaTime * 3; } } else { if (middleContent.GetComponent().alpha < 1) { middleContent.GetComponent().alpha += Time.deltaTime * 3; } } } } } private void LateUpdate() { showInfoBtn.GetComponent().anchoredPosition = CameraManager.instance.mainCamera.WorldToScreenPoint(StaticLod.instance.currentStatic.transform.position) / Screen.width * 1920.0f; } }