123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Threading.Tasks;
- using UnityEngine;
- using UnityEngine.UI;
- using UnityAsync;
- using WaitUntil = UnityAsync.WaitUntil;
- public class SPJKLayer : MonoBehaviour
- {
- public GameObject spjkItemOri;
- public Transform spjkItemContent;
-
- public List<SPJK_ObsItem> currentObsDataList = new List<SPJK_ObsItem>();
- public Text countText;
-
- public InputField _obsSearchInputField;
- public ObsPlayerPanel obsPlayerPanel;
-
-
- public Transform _obsIconContent;
- private List<ObsIconCtrl> _obsIconCtrls=new List<ObsIconCtrl>();
-
- Dictionary<string, bool> BYObsUseLib = new Dictionary<string, bool>();
- Dictionary<string, bool> TKObsUseLib = new Dictionary<string, bool>();
- public GameObject obsIconPrefab;
-
- private void Awake()
- {
- _obsIconContent = this.transform.Find("ObsIconContent").transform;
- }
- async void Start()
- {
- InitObsData();
- obsPlayerPanel = this.transform.Find("ObsPlayerPanel").GetComponent<ObsPlayerPanel>();
- obsPlayerPanel.gameObject.SetActive(false);
-
- _obsSearchInputField.onValueChanged.AddListener(SearchObsItem);
- }
- private void OnDisable()
- {
- obsPlayerPanel.gameObject.SetActive(false);
- }
- private async Task InitObsData() {
- await new WaitUntil(() =>
- {
- return GlobalData.obsDatas_by.Count > 0&&GlobalData.obsDatas_tk.Count>0;
- });
- ObsData[] obs_by = GlobalData.obsDatas_by.ToArray();
- for (int i = 0; i < obs_by.Length; i++)
- {
- int tempIndex = i;
- SPJK_ObsItem tempItem = Instantiate(spjkItemOri, spjkItemContent).GetComponent<SPJK_ObsItem>();
- tempItem.SetData(obs_by[tempIndex]);
- currentObsDataList.Add(tempItem);
- tempItem.gameObject.GetComponent<Button>().onClick.AddListener(() =>
- {
- ShowObsPanel(obs_by[tempIndex]);
- });
- }
- ObsData[] obs_tk = GlobalData.obsDatas_tk.ToArray();
- for (int i = 0; i < obs_tk.Length; i++)
- {
- int tempIndex = i;
- SPJK_ObsItem tempItem = Instantiate(spjkItemOri, spjkItemContent).GetComponent<SPJK_ObsItem>();
- tempItem.SetData(obs_tk[tempIndex]);
- currentObsDataList.Add(tempItem);
- tempItem.gameObject.GetComponent<Button>().onClick.AddListener(() =>
- {
- ShowObsPanel(obs_tk[tempIndex]);
- });
- }
- countText.text = $"监控列表 (<color=#FFFFFF>{obs_by.Length+obs_tk.Length}</color>)";
-
- for (int i = 0; i < _obsIconCtrls.Count; i++)
- {
- Destroy(_obsIconCtrls[i].gameObject);
- }
-
-
- for (int i = 0; i < GlobalData.layerUnitDatas.Count; i++)
- {
- if (GlobalData.layerUnitDatas[i].type == LayerUnitType.JK)
- {
- if (GlobalData.layerUnitDatas[i].text1 == "补元退洪闸")
- {
- BYObsUseLib.Add(GlobalData.layerUnitDatas[i].namePri, false);
- }
- else if (GlobalData.layerUnitDatas[i].text1 == "套口进洪闸")
- {
- TKObsUseLib.Add(GlobalData.layerUnitDatas[i].namePri, false);
- }
- }
- }
-
-
- foreach (string keyName in BYObsUseLib.Keys)
- {
- if (!BYObsUseLib[keyName])
- {
- ObsIconCtrl tempIcon = Instantiate(obsIconPrefab, _obsIconContent).GetComponent<ObsIconCtrl>();
- ObsData errorObs = new ObsData();
- errorObs.name = keyName + "(丢失)";
- errorObs.targetName = keyName;
- errorObs.type = obsType.BuYuanObs;
- errorObs.status = false;
- tempIcon.Init(errorObs);
- _obsIconCtrls.Add(tempIcon);
- }
- }
-
- foreach (string keyName in TKObsUseLib.Keys)
- {
- if (!TKObsUseLib[keyName])
- {
- ObsIconCtrl tempIcon = Instantiate(obsIconPrefab, _obsIconContent).GetComponent<ObsIconCtrl>();
- ObsData errorObs = new ObsData();
- errorObs.name = keyName + "(丢失)";
- errorObs.targetName = keyName;
- errorObs.type = obsType.TaoKouObs;
- errorObs.status = false;
- tempIcon.Init(errorObs);
- _obsIconCtrls.Add(tempIcon);
- }
- }
- }
-
- public void SearchObsItem(string s_name)
- {
- if (s_name.Equals(""))
- {
- for (int i = 0; i < currentObsDataList.Count; i++)
- {
- currentObsDataList[i].gameObject.SetActive(true);
- }
- }
- else
- {
- for (int i = 0; i < currentObsDataList.Count; i++)
- {
- currentObsDataList[i].gameObject.SetActive(currentObsDataList[i]._data.name.Contains(s_name));
- }
- }
- }
-
- public void ShowObsPanel(ObsData _data)
- {
- obsPlayerPanel.gameObject.SetActive(true);
- obsPlayerPanel.SetObsData(_data);
- obsPlayerPanel.SetTitle(_data.name);
- }
- }
|