SPJKLayer.cs 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Threading.Tasks;
  5. using UnityEngine;
  6. using UnityEngine.UI;
  7. using UnityAsync;
  8. using WaitUntil = UnityAsync.WaitUntil;
  9. public class SPJKLayer : MonoBehaviour
  10. {
  11. public GameObject spjkItemOri;
  12. public Transform spjkItemContent;
  13. public List<SPJK_ObsItem> currentObsDataList = new List<SPJK_ObsItem>();
  14. public Text countText;
  15. public InputField _obsSearchInputField;
  16. public ObsPlayerPanel obsPlayerPanel;
  17. async void Start()
  18. {
  19. InitObsData();
  20. obsPlayerPanel = this.transform.Find("ObsPlayerPanel").GetComponent<ObsPlayerPanel>();
  21. obsPlayerPanel.gameObject.SetActive(false);
  22. _obsSearchInputField.onValueChanged.AddListener(SearchObsItem);
  23. }
  24. private void OnDisable()
  25. {
  26. obsPlayerPanel.gameObject.SetActive(false);
  27. }
  28. private async Task InitObsData() {
  29. await new WaitUntil(() =>
  30. {
  31. return GlobalData.obsDatas_by.Count > 0&&GlobalData.obsDatas_tk.Count>0;
  32. });
  33. ObsData[] obs_by = GlobalData.obsDatas_by.ToArray();
  34. for (int i = 0; i < obs_by.Length; i++)
  35. {
  36. int tempIndex = i;
  37. SPJK_ObsItem tempItem = Instantiate(spjkItemOri, spjkItemContent).GetComponent<SPJK_ObsItem>();
  38. tempItem.SetData(obs_by[tempIndex]);
  39. currentObsDataList.Add(tempItem);
  40. tempItem.gameObject.GetComponent<Button>().onClick.AddListener(() =>
  41. {
  42. ShowObsPanel(obs_by[tempIndex]);
  43. });
  44. }
  45. ObsData[] obs_tk = GlobalData.obsDatas_tk.ToArray();
  46. for (int i = 0; i < obs_tk.Length; i++)
  47. {
  48. int tempIndex = i;
  49. SPJK_ObsItem tempItem = Instantiate(spjkItemOri, spjkItemContent).GetComponent<SPJK_ObsItem>();
  50. tempItem.SetData(obs_tk[tempIndex]);
  51. currentObsDataList.Add(tempItem);
  52. tempItem.gameObject.GetComponent<Button>().onClick.AddListener(() =>
  53. {
  54. ShowObsPanel(obs_tk[tempIndex]);
  55. });
  56. }
  57. countText.text = $"监控列表 (<color=#FFFFFF>{obs_by.Length+obs_tk.Length}</color>)";
  58. }
  59. public void SearchObsItem(string s_name)
  60. {
  61. if (s_name.Equals(""))
  62. {
  63. for (int i = 0; i < currentObsDataList.Count; i++)
  64. {
  65. currentObsDataList[i].gameObject.SetActive(true);
  66. }
  67. }
  68. else
  69. {
  70. for (int i = 0; i < currentObsDataList.Count; i++)
  71. {
  72. currentObsDataList[i].gameObject.SetActive(currentObsDataList[i]._data.name.Contains(s_name));
  73. }
  74. }
  75. }
  76. public void ShowObsPanel(ObsData _data)
  77. {
  78. obsPlayerPanel.gameObject.SetActive(true);
  79. obsPlayerPanel.SetObsData(_data);
  80. obsPlayerPanel.SetTitle(_data.name);
  81. }
  82. }