| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362 | 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<XHGKLayerData> xHGKLayerDatas16;    public List<XHGKLayerData> xHGKLayerDatas17;    public List<XHGKLayerData> xHGKLayerDatas18;    public List<XHGKLayerData> xHGKLayerDatas19;    public List<XHGKLayerData> xHGKLayerDatas20;    public List<XHGKLayerData> xHGKLayerDatas21;    public List<XHGKLayerData> xHGKLayerDatas22;    public int currentActive = 0;    public List<YearBtn> yearBtns;    public ImportBtn importThingPrefab;    public List<ImportBtn> 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<YearBtn>();        for (int i = 0; i < yearContent.childCount; i++) {            yearBtns.Add(yearContent.GetChild(i).GetComponent<YearBtn>());            int temp = i;            if (yearBtns[i].defaultActive)            {                currentActive = temp;            }            yearBtns[temp].heightY = -224 + 56 * temp;            yearBtns[temp].GetComponent<UnityEngine.UI.Button>().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<XHGKLayerData> xHGKLayerDatas) {        scrollView.GetComponent<CanvasGroup>().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<RectTransform>().SetParent(importantContent);            btn.GetComponent<RectTransform>().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<CanvasGroup>().alpha, x => scrollView.GetComponent<CanvasGroup>().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<CanvasGroup>().alpha > 0)                    {                        middleContent.GetComponent<CanvasGroup>().alpha -= Time.deltaTime * 3;                    }                }                else {                    if (middleContent.GetComponent<CanvasGroup>().alpha < 1)                    {                        middleContent.GetComponent<CanvasGroup>().alpha += Time.deltaTime * 3;                    }                }            }        }    }}
 |