Browse Source

增加B03切换套口数据的逻辑(未放开 默认展示补元)

Void_F 5 months ago
parent
commit
695ce1d2ee

+ 64 - 28
Assets/Scripts/HttpHelper.cs

@@ -45,6 +45,7 @@ public class HttpHelper : MonoBehaviour
             SendTaoKou_GetSensorData();
 
             GetBuYuanDevicesGroupInfo();
+            GetTaoKouDevicesGroupInfo();
         }
 
         if (GlobalData.pageIndex == PageIndex.Page1)
@@ -1213,6 +1214,43 @@ public class HttpHelper : MonoBehaviour
         Debug.Log("添加补元位移记:"+ GlobalData.BuYuanWeiYiDataList.Count);
     }
 
+    public async void GetTaoKouDevicesGroupInfo()
+    {
+        Debug.Log("获取套口所有渗压记");
+        //获取所有渗压记
+        foreach (var device in _devicesIdDatas.Values)
+        {
+            if (device.stationName.Equals("套口") && device.sensorType.Equals("渗压计"))
+            {
+                GlobalData.TaoKouShuiYaDataList.Add(new ShuiYaData()
+                {
+                    name = device.sensorName,
+                    value = device.realtimeValue1,
+                    type = shuiYaType.TaoKouShuiYa,
+                    targetName = $"TK_{device.sensorName}"
+                });
+            }
+        }
+        Debug.Log("添加套口渗压记:"+ GlobalData.TaoKouShuiYaDataList.Count);
+        
+        Debug.Log("获取套口所有位移记");
+        //获取所有位移记
+        foreach (var device in _devicesIdDatas.Values)
+        {
+            if (device.stationName.Equals("补元") && device.sensorType.Equals("静力水准仪"))
+            {
+                GlobalData.TaoKouWeiYiDataList.Add(new WeiYiData()
+                {
+                    name = device.sensorName,
+                    value =device.realtimeValue1,
+                    type = weiYiType.TaoKouWeiYi,
+                    targetName = $"TK_{device.sensorName}"
+                });
+            }
+        }
+        Debug.Log("添加套口位移记:"+ GlobalData.TaoKouWeiYiDataList.Count);
+    }
+    
     public async Task SendTaoKou_GetSensorData()
     {
         UnityWebRequest www = UnityWebRequest.Get(ServerAddress.API_TaoKou_GetSensorData);
@@ -1640,33 +1678,31 @@ public class HttpHelper : MonoBehaviour
             Debug.Log($"读取本地初始化设备列表成功!!! count:{tempData.total}");
             www.Dispose();
         }
-        var devicesInfo = _devicesIdDatas["上游水位计"];
-        GlobalData.BuYuanShuiWeiDataList.Add(new ShuiWeiData()
-        {
-            name = "补元上游水位",
-            targetName = "BY_ShuiWei_Up",
-            value = devicesInfo.realtimeValue1,
-            type = shuiWeiType.BuYuanShuiWei,
-            datas = new []{new SingleDevicesRequestData()
-            {
-                avgS1 = devicesInfo.realtimeValue1.ToString(),
-                timeGroup = devicesInfo.dataUpdateTime
-            }}
-        });
-        var devicesInfo1 = _devicesIdDatas["下游水位计"];
-        GlobalData.BuYuanShuiWeiDataList.Add(new ShuiWeiData()
-        {
-            name = "补元下游水位",
-            targetName = "BY_ShuiWei_Down",
-            value = devicesInfo1.realtimeValue1,
-            type = shuiWeiType.BuYuanShuiWei,
-            datas = new []{new SingleDevicesRequestData()
-            {
-                avgS1 = devicesInfo1.realtimeValue1.ToString(),
-                timeGroup = devicesInfo1.dataUpdateTime
-            }}
-        });
+        // var devicesInfo = _devicesIdDatas["上游水位计"];
+        // GlobalData.BuYuanShuiWeiDataList.Add(new ShuiWeiData()
+        // {
+        //     name = "补元上游水位",
+        //     targetName = "BY_ShuiWei_Up",
+        //     value = devicesInfo.realtimeValue1,
+        //     type = shuiWeiType.BuYuanShuiWei,
+        //     datas = new []{new SingleDevicesRequestData()
+        //     {
+        //         avgS1 = devicesInfo.realtimeValue1.ToString(),
+        //         timeGroup = devicesInfo.dataUpdateTime
+        //     }}
+        // });
+        // var devicesInfo1 = _devicesIdDatas["下游水位计"];
+        // GlobalData.BuYuanShuiWeiDataList.Add(new ShuiWeiData()
+        // {
+        //     name = "补元下游水位",
+        //     targetName = "BY_ShuiWei_Down",
+        //     value = devicesInfo1.realtimeValue1,
+        //     type = shuiWeiType.BuYuanShuiWei,
+        //     datas = new []{new SingleDevicesRequestData()
+        //     {
+        //         avgS1 = devicesInfo1.realtimeValue1.ToString(),
+        //         timeGroup = devicesInfo1.dataUpdateTime
+        //     }}
+        // });
     }
-
-   
 }

+ 1 - 0
Assets/Scripts/UI/Data/GlobalData.cs

@@ -66,6 +66,7 @@ public class GlobalData
     /// 一张图第六页水位数据
     /// </summary>
     public static List<ShuiWeiData> BuYuanShuiWeiDataList = new List<ShuiWeiData>();
+    public static List<ShuiWeiData> TaoKouShuiWeiDataList = new List<ShuiWeiData>();
 
     /// <summary>
     /// 一张图第六页三线水位数据

+ 104 - 90
Assets/Scripts/UI/UIView/GCJK/GCJKLayer.cs

@@ -199,24 +199,20 @@ public class GCJKLayer : YZTRootLayer
 
     private InputField _obsSearchInputField;
 
-
     //水位图标
     [Header("水位数据")] public GameObject shuiweiIconPrefab;
     private List<ShuiWeiIconCtrl> _shuiWeiIconCtrls = new List<ShuiWeiIconCtrl>();
     private Transform _shuiWeiIconContent;
-    private bool creatShuiWeiIcon = false;
 
     //水压
     public GameObject shuiYaIconPrefab;
     private List<ShuiYaIconCtrl> _shuiYaIconCtrls = new List<ShuiYaIconCtrl>();
     private Transform _shuiYaIconContent;
-    private bool creatShuiYaIcon = false;
 
     //位移
     public GameObject weiYiIconPrefab;
     private List<WeiYiIconCtrl> _weiYiIconCtrls = new List<WeiYiIconCtrl>();
     private Transform _weiYiIconContent;
-    private bool creatWeiYiIcon = false;
 
     private Toggle obsToggle;
     private Toggle shuiWeiToggle;
@@ -250,6 +246,7 @@ public class GCJKLayer : YZTRootLayer
 
     public GameObject runtimePointObj;
 
+    private int currentDataType = -1;
 
     private void Awake()
     {
@@ -265,18 +262,12 @@ public class GCJKLayer : YZTRootLayer
     {
         StaticLod.instance.OnFoucusStatic(0);
 
-        bool waitInitZhaZhanJianKongData = false;
         if (GlobalData.buYuanSensorData != null)
         {
             if (GlobalData.buYuanSensorData.data.Count < 1)
             {
                 await HttpHelper._Instance.SendBuYuan_GetSensorData();
             }
-
-            if (GlobalData.buYuanSensorData.data.Count > 0)
-            {
-                waitInitZhaZhanJianKongData = true;
-            }
         }
 
         if (GlobalData.taoKouSensorData != null)
@@ -285,16 +276,6 @@ public class GCJKLayer : YZTRootLayer
             {
                 await HttpHelper._Instance.SendTaoKou_GetSensorData();
             }
-
-            if (GlobalData.taoKouSensorData.data.Count > 0)
-            {
-                waitInitZhaZhanJianKongData = true;
-            }
-        }
-
-        if (waitInitZhaZhanJianKongData)
-        {
-            SetZhaZhanJianKongData();
         }
 
         if (GlobalData.BuYuanShuiWeiDataList.Count < 1)
@@ -302,35 +283,17 @@ public class GCJKLayer : YZTRootLayer
             await HttpHelper._Instance.InitSWYJData();
         }
 
-        if (!creatShuiWeiIcon && GlobalData.BuYuanShuiWeiDataList.Count > 0)
-        {
-            CreatShuiWeiIcon();
-            FindShuiWeiTargetObje();
-        }
-
         if (GlobalData.BuYuanShuiYaDataList.Count < 1)
         {
             HttpHelper._Instance.GetBuYuanDevicesGroupInfo();
         }
 
-        if (!creatShuiYaIcon && GlobalData.BuYuanShuiWeiDataList.Count > 0)
-        {
-            CreatShuiYaIcon();
-            FindShuiYaTargetObje();
-        }
-
-        if (!creatWeiYiIcon && GlobalData.BuYuanWeiYiDataList.Count > 0)
+        if (GlobalData.TaoKouShuiYaDataList.Count < 1)
         {
-            CreatWeiYiIcon();
-            FindWeiYiTargetObje();
+            HttpHelper._Instance.GetTaoKouDevicesGroupInfo();
         }
 
-        SetObsIconActive(obsToggle.isOn);
-        SetShuiWeiIconActive(shuiWeiToggle.isOn);
-        SetShuiYaIconActive(shuiYaToggle.isOn);
-        SetWeiYiIconActive(weiYiToggle.isOn);
-        
-        SetGongChengLieBiaoData();
+        SetCurrentDataToPanel(0);
     }
 
 
@@ -607,6 +570,39 @@ public class GCJKLayer : YZTRootLayer
         }
     }
 
+
+    public void SetCurrentDataToPanel(int type)
+    {
+        if (currentDataType == type)
+        {
+            return;
+        }
+
+        currentDataType = type;
+
+        SetZhaZhanJianKongData();
+
+        //水位图标
+        CreatShuiWeiIcon();
+        FindShuiWeiTargetObje();
+
+        //水压图标
+        CreatShuiYaIcon();
+        FindShuiYaTargetObje();
+
+        //位移图标
+        CreatWeiYiIcon();
+        FindWeiYiTargetObje();
+
+        SetObsIconActive(obsToggle.isOn);
+        SetShuiWeiIconActive(shuiWeiToggle.isOn);
+        SetShuiYaIconActive(shuiYaToggle.isOn);
+        SetWeiYiIconActive(weiYiToggle.isOn);
+
+        SetGongChengLieBiaoData();
+    }
+
+
     public void SetZhaZhanJianKongData()
     {
         List<ZhaZhanJianKongData> datas = new List<ZhaZhanJianKongData>();
@@ -615,7 +611,7 @@ public class GCJKLayer : YZTRootLayer
             datas.Add(new ZhaZhanJianKongData()
             {
                 name = "闸门_" + GlobalData.buYuanSensorData.data[i].sensor_id,
-                openValue = GlobalData.buYuanSensorData.data[i].opening_degree*0.01f,
+                openValue = GlobalData.buYuanSensorData.data[i].opening_degree * 0.01f,
                 state = GlobalData.buYuanSensorData.data[i].gate_open
                     ? ZhaZhanState.open
                     : ZhaZhanState.close,
@@ -627,7 +623,7 @@ public class GCJKLayer : YZTRootLayer
             datas.Add(new ZhaZhanJianKongData()
             {
                 name = "闸门_" + GlobalData.taoKouSensorData.data[i].sensor_id,
-                openValue = GlobalData.taoKouSensorData.data[i].opening_degree*0.01f,
+                openValue = GlobalData.taoKouSensorData.data[i].opening_degree * 0.01f,
                 state = GlobalData.taoKouSensorData.data[i].gate_open
                     ? ZhaZhanState.open
                     : ZhaZhanState.close,
@@ -684,7 +680,7 @@ public class GCJKLayer : YZTRootLayer
     {
         List<GongChengLieBiaoData> datas = new List<GongChengLieBiaoData>();
         //水位
-        foreach (var tempData in GlobalData.BuYuanShuiWeiDataList)
+        foreach (var tempData in currentDataType==0?GlobalData.BuYuanShuiWeiDataList:GlobalData.TaoKouShuiWeiDataList)
         {
             GongChengLieBiaoData tempLieBiaoData = new GongChengLieBiaoData();
             tempLieBiaoData.name = tempData.name;
@@ -694,7 +690,7 @@ public class GCJKLayer : YZTRootLayer
         }
 
         //水压
-        foreach (var tempData in GlobalData.BuYuanShuiYaDataList)
+        foreach (var tempData in currentDataType==0?GlobalData.BuYuanShuiYaDataList:GlobalData.TaoKouShuiYaDataList)
         {
             GongChengLieBiaoData tempLieBiaoData = new GongChengLieBiaoData();
             tempLieBiaoData.name = tempData.name;
@@ -704,7 +700,7 @@ public class GCJKLayer : YZTRootLayer
         }
 
         //位移
-        foreach (var tempData in GlobalData.BuYuanWeiYiDataList)
+        foreach (var tempData in currentDataType==0?GlobalData.BuYuanWeiYiDataList:GlobalData.TaoKouWeiYiDataList)
         {
             GongChengLieBiaoData tempLieBiaoData = new GongChengLieBiaoData();
             tempLieBiaoData.name = tempData.name;
@@ -714,15 +710,7 @@ public class GCJKLayer : YZTRootLayer
         }
 
         //监控
-        foreach (var tempData in GlobalData.obsDatas_by)
-        {
-            GongChengLieBiaoData tempLieBiaoData = new GongChengLieBiaoData();
-            tempLieBiaoData.name = tempData.name;
-            tempLieBiaoData.type = GongChengType.shiPin;
-            tempLieBiaoData.state = tempData.status ? GongChengState.normal : GongChengState.warning;
-            datas.Add(tempLieBiaoData);
-        }
-        foreach (var tempData in GlobalData.obsDatas_tk)
+        foreach (var tempData in currentDataType==0?GlobalData.obsDatas_by:GlobalData.obsDatas_tk)
         {
             GongChengLieBiaoData tempLieBiaoData = new GongChengLieBiaoData();
             tempLieBiaoData.name = tempData.name;
@@ -809,33 +797,46 @@ public class GCJKLayer : YZTRootLayer
     //监控列表
     public async void CreatObsItem()
     {
-        await new WaitUntil(() => { return GlobalData.obsDatas_by.Count > 0&& GlobalData.obsDatas_tk.Count>0; });
+        await new WaitUntil(() => { return GlobalData.obsDatas_by.Count > 0 && GlobalData.obsDatas_tk.Count > 0; });
         _obsItems = new List<ObsItem>();
         _obsIconCtrls = new List<ObsIconCtrl>();
+        for (int i = 0; i < _obsItems.Count; i++)
+        {
+            Destroy(_obsItems[i].gameObject);
+        }
+        for (int i = 0; i < _obsIconCtrls.Count; i++)
+        {
+            Destroy(_obsIconCtrls[i].gameObject);
+        }
         //Debug.Log("监控列表数量:"+GlobalData.obsDatas_by.Count);
-        for (int i = 0; i < GlobalData.obsDatas_by.Count; i++)
+        if (currentDataType == 0)
         {
-            ObsItem tempItem = Instantiate(obsItemPrefab, obsItemContent).GetComponent<ObsItem>();
-            tempItem.SetData(GlobalData.obsDatas_by[i]);
-            _obsItems.Add(tempItem);
-            ObsIconCtrl tempIcon = Instantiate(obsIconPrefab, _obsIconContent).GetComponent<ObsIconCtrl>();
-            Debug.Log(GlobalData.obsDatas_by[i].name +" "+GlobalData.obsDatas_by[i].targetName);
-            tempIcon.Init(GlobalData.obsDatas_by[i]);
-            _obsIconCtrls.Add(tempIcon);
-            //Debug.Log(StaticLod.instance.GetStaticObj(GlobalData.obsDatas[i].name).gameObject.name);
+            for (int i = 0; i < GlobalData.obsDatas_by.Count; i++)
+            {
+                ObsItem tempItem = Instantiate(obsItemPrefab, obsItemContent).GetComponent<ObsItem>();
+                tempItem.SetData(GlobalData.obsDatas_by[i]);
+                _obsItems.Add(tempItem);
+                ObsIconCtrl tempIcon = Instantiate(obsIconPrefab, _obsIconContent).GetComponent<ObsIconCtrl>();
+                Debug.Log(GlobalData.obsDatas_by[i].name + " " + GlobalData.obsDatas_by[i].targetName);
+                tempIcon.Init(GlobalData.obsDatas_by[i]);
+                _obsIconCtrls.Add(tempIcon);
+                //Debug.Log(StaticLod.instance.GetStaticObj(GlobalData.obsDatas[i].name).gameObject.name);
+            }
+        }
+        else
+        {
+            //Debug.Log($"创建补元监控对象:{_obsItems.Count} {_obsIconCtrls.Count} {GlobalData.obsDatas_by.Count} {GlobalData.obsDatas_tk.Count}");
+            for (int i = 0; i < GlobalData.obsDatas_tk.Count; i++)
+            {
+                ObsItem tempItem = Instantiate(obsItemPrefab, obsItemContent).GetComponent<ObsItem>();
+                tempItem.SetData(GlobalData.obsDatas_tk[i]);
+                _obsItems.Add(tempItem);
+                ObsIconCtrl tempIcon = Instantiate(obsIconPrefab, _obsIconContent).GetComponent<ObsIconCtrl>();
+                tempIcon.Init(GlobalData.obsDatas_tk[i]);
+                _obsIconCtrls.Add(tempIcon);
+                //Debug.Log(StaticLod.instance.GetStaticObj(GlobalData.obsDatas[i].name).gameObject.name);
+            }
         }
-        //Debug.Log($"创建补元监控对象:{_obsItems.Count} {_obsIconCtrls.Count} {GlobalData.obsDatas_by.Count} {GlobalData.obsDatas_tk.Count}");
-        // for (int i = 0; i < GlobalData.obsDatas_tk.Count; i++)
-        // {
-        //     ObsItem tempItem = Instantiate(obsItemPrefab, obsItemContent).GetComponent<ObsItem>();
-        //     tempItem.SetData(GlobalData.obsDatas_tk[i]);
-        //     _obsItems.Add(tempItem);
-        //     ObsIconCtrl tempIcon = Instantiate(obsIconPrefab, _obsIconContent).GetComponent<ObsIconCtrl>();
-        //     tempIcon.Init(GlobalData.obsDatas_tk[i]);
-        //     _obsIconCtrls.Add(tempIcon);
-        //     //Debug.Log(StaticLod.instance.GetStaticObj(GlobalData.obsDatas[i].name).gameObject.name);
-        // }
-
         SetObsIconActive(obsToggle.isOn);
     }
 
@@ -926,16 +927,22 @@ public class GCJKLayer : YZTRootLayer
     //水位图标
     public void CreatShuiWeiIcon()
     {
+        for (int i = 0; i < _shuiWeiIconCtrls.Count; i++)
+        {
+            Destroy(_shuiWeiIconCtrls[i].gameObject);
+        }
+
         _shuiWeiIconCtrls = new List<ShuiWeiIconCtrl>();
-        for (int i = 0; i < GlobalData.BuYuanShuiWeiDataList.Count; i++)
+
+        var DataList = currentDataType == 0 ? GlobalData.BuYuanShuiWeiDataList : GlobalData.TaoKouShuiWeiDataList;
+        for (int i = 0; i < DataList.Count; i++)
         {
             ShuiWeiIconCtrl tempIcon =
                 Instantiate(shuiweiIconPrefab, _shuiWeiIconContent).GetComponent<ShuiWeiIconCtrl>();
-            tempIcon.Init(GlobalData.BuYuanShuiWeiDataList[i]);
+            tempIcon.Init(DataList[i]);
             _shuiWeiIconCtrls.Add(tempIcon);
         }
-
-        creatShuiWeiIcon = true;
+        Debug.Log(DataList.Count);
     }
 
     //查找场景中的水位坐标对象
@@ -979,15 +986,20 @@ public class GCJKLayer : YZTRootLayer
     //水压图标
     public void CreatShuiYaIcon()
     {
+        for (int i = 0; i < _shuiYaIconCtrls.Count; i++)
+        {
+            Destroy(_shuiYaIconCtrls[i].gameObject);
+        }
+
         _shuiYaIconCtrls = new List<ShuiYaIconCtrl>();
-        for (int i = 0; i < GlobalData.BuYuanShuiYaDataList.Count; i++)
+
+        var DataList = currentDataType == 0 ? GlobalData.BuYuanShuiYaDataList : GlobalData.TaoKouShuiYaDataList;
+        for (int i = 0; i < DataList.Count; i++)
         {
             ShuiYaIconCtrl tempIcon = Instantiate(shuiYaIconPrefab, _shuiYaIconContent).GetComponent<ShuiYaIconCtrl>();
-            tempIcon.Init(GlobalData.BuYuanShuiYaDataList[i]);
+            tempIcon.Init(DataList[i]);
             _shuiYaIconCtrls.Add(tempIcon);
         }
-
-        creatShuiYaIcon = true;
     }
 
     public void FindShuiYaTargetObje()
@@ -1030,15 +1042,18 @@ public class GCJKLayer : YZTRootLayer
     //位移图标
     public void CreatWeiYiIcon()
     {
+        for (int i = 0; i < _weiYiIconCtrls.Count; i++)
+        {
+            Destroy(_weiYiIconCtrls[i].gameObject);
+        }
         _weiYiIconCtrls = new List<WeiYiIconCtrl>();
-        for (int i = 0; i < GlobalData.BuYuanWeiYiDataList.Count; i++)
+        var DataList = currentDataType == 0 ? GlobalData.BuYuanWeiYiDataList : GlobalData.TaoKouWeiYiDataList;
+        for (int i = 0; i < DataList.Count; i++)
         {
             WeiYiIconCtrl tempIcon = Instantiate(weiYiIconPrefab, _weiYiIconContent).GetComponent<WeiYiIconCtrl>();
-            tempIcon.Init(GlobalData.BuYuanWeiYiDataList[i]);
+            tempIcon.Init(DataList[i]);
             _weiYiIconCtrls.Add(tempIcon);
         }
-
-        creatWeiYiIcon = true;
     }
 
     public void FindWeiYiTargetObje()
@@ -1047,7 +1062,6 @@ public class GCJKLayer : YZTRootLayer
         {
             return;
         }
-
         GameObject[] BY_targs = GameObject.FindGameObjectsWithTag(weiYiType.BuYuanWeiYi.ToString());
         GameObject[] TK_targs = GameObject.FindGameObjectsWithTag(weiYiType.TaoKouWeiYi.ToString());
         for (int i = 0; i < _weiYiIconCtrls.Count; i++)