| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302 | using System;using System.Collections;using System.Collections.Generic;using System.Threading.Tasks;using UnityEngine;using UnityEngine.UI;using UnityAsync;using WaitUntil = UnityAsync.WaitUntil;using XCharts.Runtime;public class ZMJKLayer : MonoBehaviour{    public GameObject ZhaZhanItemOri;    public Transform itemContent;    public Text zhaZhanCount;    public GameObject gongChengPanel;    public Button closeButton;    public Text zhaZhanMingCheng;    public Text zhaQianShuiWei;    public Text zhaHouShuiWei;    public Text zhaMenKaiDu;    public Text guoZhaLiuLiang;    public Button byBtn;    public Button tkBtn;    public BarChart shuiweiChart;    public InputField _zmSearchInputField;    public List<ZhaZhanItem> currentZMDataList = new List<ZhaZhanItem>();    public GameObject targetObj;    public bool showGongPanel = false;    private Camera _camera;    public GameObject zhaMenIconOri;    public Transform zhaMenContent;    public List<ZhaMenIconCtrl> zhaMenIconList = new List<ZhaMenIconCtrl>();        public GameObject byThreeLine;    public GameObject tkThreesLine;    private void Awake()    {        closeButton.onClick.AddListener(() =>        {            gongChengPanel.SetActive(false);            showGongPanel = false;        });        gongChengPanel.SetActive(false);        showGongPanel = false;    }    private void OnEnable()    {        _camera = CameraManager.instance.mainCamera;        StaticLod.instance.OnFoucusStatic(0);    }    // Start is called before the first frame update    async void Start()    {        InitFloorGateData();        _zmSearchInputField.onValueChanged.AddListener(SearchObsItem);        byBtn.onClick.AddListener(() =>        {            byBtn.GetComponent<CanvasGroup>().alpha = 1;            tkBtn.GetComponent<CanvasGroup>().alpha = 0.5f;            StaticLod.instance.OnFoucusStatic("BuYuan");        });        tkBtn.onClick.AddListener(() =>        {            byBtn.GetComponent<CanvasGroup>().alpha = 0.5f;            tkBtn.GetComponent<CanvasGroup>().alpha = 1f;            StaticLod.instance.OnFoucusStatic("TaoKou");        });    }    async Task InitFloorGateData()    {        await new WaitUntil(() => { return GlobalData.floorGateData.success; });        float[] byV3 = new float[GlobalData.floorGateData.buYuan.Length];        for (int i = 0; i < GlobalData.floorGateData.buYuan.Length; i++)        {            int tempIndex = i;            ZhaZhanItem tempItem = Instantiate(ZhaZhanItemOri, itemContent).GetComponent<ZhaZhanItem>();            tempItem.SetData(GlobalData.floorGateData.buYuan[tempIndex], $"补元-{tempIndex + 1}#闸门");            byV3[tempIndex] = GlobalData.floorGateData.buYuan[tempIndex].opening_degree;            //Debug.Log($"补元闸门-{tempIndex + 1}:{byV3[tempIndex]}");            tempItem.gameObject.GetComponent<Button>().onClick.AddListener(() =>            {                OpenZhaMenInfoPanel(0, tempIndex, tempItem);            });            currentZMDataList.Add(tempItem);            ZhaMenIconCtrl tempIcon = Instantiate(zhaMenIconOri, zhaMenContent).GetComponent<ZhaMenIconCtrl>();            tempIcon.Init(GlobalData.floorGateData.buYuan[tempIndex], $"补元:-{tempIndex + 1}#闸门",                StaticLod.instance.GetStaticObj($"BY_ZM_{tempIndex + 1:00}"),                () =>                {                    OpenZhaMenInfoPanel(0, tempIndex, tempItem);                });            zhaMenIconList.Add(tempIcon);        }        ActionInstance._Instance.ModelAni_On?.Invoke(AniType.buYuan, byV3);        float[] tkV3 = new float[GlobalData.floorGateData.taoKou.Length];        for (int i = 0; i < GlobalData.floorGateData.taoKou.Length; i++)        {            int tempIndex = i;            ZhaZhanItem tempItem = Instantiate(ZhaZhanItemOri, itemContent).GetComponent<ZhaZhanItem>();            tempItem.SetData(GlobalData.floorGateData.taoKou[tempIndex], $"套口:{tempIndex + 1}#闸门");            tkV3[tempIndex] = GlobalData.floorGateData.taoKou[tempIndex].opening_degree;            tempItem.gameObject.GetComponent<Button>().onClick.AddListener(() =>            {                OpenZhaMenInfoPanel(1, tempIndex, tempItem);            });            currentZMDataList.Add(tempItem);                        ZhaMenIconCtrl tempIcon = Instantiate(zhaMenIconOri, zhaMenContent).GetComponent<ZhaMenIconCtrl>();            tempIcon.Init(GlobalData.floorGateData.taoKou[tempIndex], $"套口:-{tempIndex + 1}#闸门",                StaticLod.instance.GetStaticObj($"TK_ZM_{tempIndex + 1:00}"), () =>                {                    OpenZhaMenInfoPanel(1, tempIndex, tempItem);                });            zhaMenIconList.Add(tempIcon);        }        ActionInstance._Instance.ModelAni_On?.Invoke(AniType.taoKou, tkV3);        int totalCount = GlobalData.floorGateData.BuYuanTotalGates + GlobalData.floorGateData.TaoKouTotalGates;        zhaZhanCount.text = $"闸门列表 (<color=#FFFFFF>{totalCount}</color>)";            }    public void OpenZhaMenInfoPanel(int type, int _index, ZhaZhanItem itemData)    {        string staticNameHead = type == 0 ? "BY_ZM_" : "TK_ZM_";        StaticLod.instance.OnFoucusStatic($"{staticNameHead}{_index + 1:00}");        targetObj = StaticLod.instance.GetStaticObj($"{staticNameHead}{_index + 1:00}");        gongChengPanel.SetActive(true);        showGongPanel = true;        zhaZhanMingCheng.text = itemData._name;        var floorGateData = type == 0 ? GlobalData.floorGateData.buYuan : GlobalData.floorGateData.taoKou;        zhaMenKaiDu.text = $"{floorGateData[_index].opening_degree:0.00}<size=14><color=#A5BFE2>m</color></size>";        guoZhaLiuLiang.text = $"-<size=14><color=#A5BFE2>m\u00b3/s</color></size>";        if (type == 0)        {            string swUp = null;            string swDown = null;            string swUpName = "";            string swDownName = "";            for (int i = 0; i < GlobalData.swDatas.Count; i++)            {                if (GlobalData.swDatas[i].stnm == "补元(闸上)")                {                    swUp = GlobalData.swDatas[i].upz;                    swUpName = GlobalData.swDatas[i].stnm;                }                if (GlobalData.swDatas[i].stnm == "补元(闸下)")                {                    swDown = GlobalData.swDatas[i].dwz;                    swDownName = GlobalData.swDatas[i].stnm;                }            }            zhaQianShuiWei.text = swUp == null ? $"- <size=14><color=#A5BFE2>m</color></size>" : $"{swUp} <size=14><color=#A5BFE2>m</color></size>";            zhaHouShuiWei.text = swDown == null ? $"- <size=14><color=#A5BFE2>m</color></size>" : $"{swDown} <size=14><color=#A5BFE2>m</color></size>";        }        else        {            string swUp = null;            string swDown =null;            string swUpName="";            string swDownName="";            for (int i = 0; i < GlobalData.swDatas.Count; i++)            {                if (GlobalData.swDatas[i].stnm == "套口(闸上)")                {                    swUp = GlobalData.swDatas[i].upz;                    swUpName = GlobalData.swDatas[i].stnm;                }                if (GlobalData.swDatas[i].stnm == "套口(闸下)")                {                    swDown = GlobalData.swDatas[i].dwz;                    swDownName = GlobalData.swDatas[i].stnm;                }            }            zhaQianShuiWei.text = swUp == null ? $"- <size=14><color=#A5BFE2>m</color></size>" : $"{swUp} <size=14><color=#A5BFE2>m</color></size>";            zhaHouShuiWei.text = swDown == null ? $"- <size=14><color=#A5BFE2>m</color></size>" : $"{swDown} <size=14><color=#A5BFE2>m</color></size>";        }        //for (int i = 0; i < GlobalData.swDatas.Count; i++)        //{        //    Debug.Log("111111111111:" + GlobalData.swDatas[i].stnm);        //    Debug.Log("111111111111:" + GlobalData.swDatas[i].upz);        //    Debug.Log("111111111111:" + GlobalData.swDatas[i].dwz);        //}        var shuiweiData = type == 0 ? GlobalData.floorGateData.swzxtBY : GlobalData.floorGateData.swzxtTK;        var finalData = new CharData_water[shuiweiData.Length];                 for (int i = 0; i < shuiweiData.Length; i++)        {            finalData[i] = shuiweiData[shuiweiData.Length - 1 - i];        }                XAxis tempXaxis = shuiweiChart.GetChartComponent<XAxis>();        tempXaxis.data.Clear();        for (int i = 0; i < finalData.Length; i++)        {            tempXaxis.AddData(finalData[i].key);        }        var tempSeries = shuiweiChart.series;        tempSeries[0].serieName = "水位/m";        SerieData[] tempDatas = new SerieData[finalData.Length];        for (int i = 0; i < tempDatas.Length; i++)        {            tempDatas[i] = new SerieData();            tempDatas[i].data = new List<double>();            tempDatas[i].data.Add(i);            string value = finalData[i].value;            if (finalData[i].value == "-") {                value = "-1";            }            tempDatas[i].data.Add(float.Parse(value));        }        tempSeries[0].data.Clear();        tempSeries[0].data.AddRange(tempDatas);                if (type == 0)        {            byThreeLine.gameObject.SetActive(true);            tkThreesLine.gameObject.SetActive(false);        }        else        {            byThreeLine.gameObject.SetActive(false);            tkThreesLine.gameObject.SetActive(true);        }            }    public void SearchObsItem(string s_name)    {        if (s_name.Equals(""))        {            for (int i = 0; i < currentZMDataList.Count; i++)            {                currentZMDataList[i].gameObject.SetActive(true);            }        }        else        {            for (int i = 0; i < currentZMDataList.Count; i++)            {                currentZMDataList[i].gameObject.SetActive(currentZMDataList[i]._name.Contains(s_name));            }        }    }    // Update is called once per frame    void Update()    {        if (showGongPanel)        {            if (targetObj != null)            {                if (IsObjectInCameraView(targetObj.transform, _camera))                {                    gongChengPanel.transform.position = _camera.WorldToScreenPoint(targetObj.transform.position);                }            }        }    }    bool IsObjectInCameraView(Transform objectTransform, Camera camera)    {        Vector3 objectScreenPosition = camera.WorldToScreenPoint(objectTransform.position);        return objectScreenPosition.z > 0 &&               objectScreenPosition.x > 0 &&               objectScreenPosition.x < Screen.width &&               objectScreenPosition.y > 0 &&               objectScreenPosition.y < Screen.height;    }}
 |