| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 | 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;    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>)";    }        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);    }}
 |