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>();
- 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 * 0.01f;
- //Debug.Log($"补元闸门-{tempIndex + 1}:{byV3[tempIndex]}");
- tempItem.gameObject.GetComponent<Button>().onClick.AddListener(() =>
- {
- OpenZhaMenInfoPanel(0, tempIndex, tempItem);
- //
- // StaticLod.instance.OnFoucusStatic($"BY_ZM_{tempIndex + 1:00}");
- // targetObj = StaticLod.instance.GetStaticObj($"BY_ZM_{tempIndex + 1:00}");
- // gongChengPanel.SetActive(true);
- // showGongPanel = true;
- // zhaZhanMingCheng.text = tempItem._name;
- // zhaMenKaiDu.text =
- // $"{GlobalData.floorGateData.buYuan[tempIndex].opening_degree:0.00}<size=14><color=#A5BFE2>%</color></size>";
- // //guoZhaLiuLiang.text = $"{GlobalData.floorGateData.buYuan[tempIndex].CurrentFlow}<size=14><color=#A5BFE2>m\u00b3/s</color></size>";
- // guoZhaLiuLiang.text = $"-<size=14><color=#A5BFE2>m\u00b3/s</color></size>";
- //
- // //zhaQianShuiWei.text = $"{GlobalData.floorGateData.BuYuan.FloodGates[tempIndex]} <size=14><color=#A5BFE2>m</color></size>";
- // zhaQianShuiWei.text = $"- <size=14><color=#A5BFE2>m</color></size>";
- // //zhaHouShuiWei.text = $"{GlobalData.floorGateData.BuYuan.FloodGates[tempIndex]} <size=14><color=#A5BFE2>m</color></size>";
- // zhaHouShuiWei.text = $"{GlobalData.floorGateData.buYuanSW} <size=14><color=#A5BFE2>m</color></size>";
- //
- // var shuiweiData = GlobalData.floorGateData.swzxtBY;
- //
- // XAxis tempXaxis = shuiweiChart.GetChartComponent<XAxis>();
- // tempXaxis.data.Clear();
- // for (int i = 0; i < shuiweiData.Length; i++)
- // {
- // tempXaxis.AddData(shuiweiData[i].key);
- // }
- //
- // var tempSeries = shuiweiChart.series;
- // tempSeries[0].serieName = "水位";
- // tempSeries[1].serieName = "水位";
- // SerieData[] tempDatas = new SerieData[shuiweiData.Length];
- // for (int i = 0; i < tempDatas.Length; i++)
- // {
- // tempDatas[i] = new SerieData();
- // tempDatas[i].data = new List<double>();
- // tempDatas[i].data.Add(i);
- // tempDatas[i].data.Add(shuiweiData[i].value);
- // }
- //
- // tempSeries[0].data.Clear();
- // tempSeries[0].data.AddRange(tempDatas);
- // tempSeries[1].data.Clear();
- // tempSeries[1].data.AddRange(tempDatas);
- });
- 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}"));
- 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 * 0.01f;
- tempItem.gameObject.GetComponent<Button>().onClick.AddListener(() =>
- {
- OpenZhaMenInfoPanel(1, tempIndex, tempItem);
- // StaticLod.instance.OnFoucusStatic($"TK_ZM_{tempIndex + 1:00}");
- // targetObj = StaticLod.instance.GetStaticObj($"TK_ZM_{tempIndex + 1:00}");
- // gongChengPanel.SetActive(true);
- // showGongPanel = true;
- // zhaZhanMingCheng.text = tempItem._name;
- // zhaMenKaiDu.text =
- // $"{GlobalData.floorGateData.taoKou[tempIndex].opening_degree:0.00}<size=14><color=#A5BFE2>%</color></size>";
- // //guoZhaLiuLiang.text = $"{GlobalData.floorGateData.taoKou[tempIndex].CurrentFlow}<size=14><color=#A5BFE2>m\u00b3/s</color></size>";
- // guoZhaLiuLiang.text = $"-<size=14><color=#A5BFE2>m\u00b3/s</color></size>";
- //
- // //zhaQianShuiWei.text = $"{GlobalData.floorGateData.BuYuan.FloodGates[tempIndex]} <size=14><color=#A5BFE2>m</color></size>";
- // zhaQianShuiWei.text = $"{GlobalData.floorGateData.taoKouSW} <size=14><color=#A5BFE2>m</color></size>";
- // //zhaHouShuiWei.text = $"{GlobalData.floorGateData.BuYuan.FloodGates[tempIndex]} <size=14><color=#A5BFE2>m</color></size>";
- // zhaHouShuiWei.text = $"-<size=14><color=#A5BFE2>m</color></size>";
- //
- // var shuiweiData = GlobalData.floorGateData.swzxtTK;
- // XAxis tempXaxis = shuiweiChart.GetChartComponent<XAxis>();
- // tempXaxis.data.Clear();
- // for (int i = 0; i < shuiweiData.Length; i++)
- // {
- // tempXaxis.AddData(shuiweiData[i].key);
- // }
- //
- // var tempSeries = shuiweiChart.series;
- // tempSeries[0].serieName = "水位";
- // tempSeries[1].serieName = "水位";
- // SerieData[] tempDatas = new SerieData[shuiweiData.Length];
- // for (int i = 0; i < tempDatas.Length; i++)
- // {
- // tempDatas[i] = new SerieData();
- // tempDatas[i].data = new List<double>();
- // tempDatas[i].data.Add(i);
- // tempDatas[i].data.Add(float.Parse(shuiweiData[i].value.ToString("F2")));
- // }
- //
- // tempSeries[0].data.Clear();
- // tempSeries[0].data.AddRange(tempDatas);
- // tempSeries[1].data.Clear();
- // tempSeries[1].data.AddRange(tempDatas);
- });
- 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}"));
- 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>%</color></size>";
- guoZhaLiuLiang.text = $"-<size=14><color=#A5BFE2>m\u00b3/s</color></size>";
- zhaQianShuiWei.text = $"- <size=14><color=#A5BFE2>m</color></size>";
- var floorGateData_sw = type == 0 ? GlobalData.floorGateData.buYuanSW : GlobalData.floorGateData.taoKouSW;
- zhaHouShuiWei.text = $"{floorGateData_sw} <size=14><color=#A5BFE2>m</color></size>";
- var shuiweiData = type == 0 ? GlobalData.floorGateData.swzxtBY : GlobalData.floorGateData.swzxtTK;
- XAxis tempXaxis = shuiweiChart.GetChartComponent<XAxis>();
- tempXaxis.data.Clear();
- for (int i = 0; i < shuiweiData.Length; i++)
- {
- tempXaxis.AddData(shuiweiData[i].key);
- }
- var tempSeries = shuiweiChart.series;
- tempSeries[0].serieName = "水位";
- tempSeries[1].serieName = "水位";
- SerieData[] tempDatas = new SerieData[shuiweiData.Length];
- for (int i = 0; i < tempDatas.Length; i++)
- {
- tempDatas[i] = new SerieData();
- tempDatas[i].data = new List<double>();
- tempDatas[i].data.Add(i);
- tempDatas[i].data.Add(shuiweiData[i].value);
- }
- tempSeries[0].data.Clear();
- tempSeries[0].data.AddRange(tempDatas);
- tempSeries[1].data.Clear();
- tempSeries[1].data.AddRange(tempDatas);
- }
- 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;
- }
- }
|