SPJKLayer.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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. public Transform _obsIconContent;
  18. private List<ObsIconCtrl> _obsIconCtrls=new List<ObsIconCtrl>();
  19. Dictionary<string, bool> BYObsUseLib = new Dictionary<string, bool>();
  20. Dictionary<string, bool> TKObsUseLib = new Dictionary<string, bool>();
  21. public GameObject obsIconPrefab;
  22. private void Awake()
  23. {
  24. _obsIconContent = this.transform.Find("ObsIconContent").transform;
  25. }
  26. async void Start()
  27. {
  28. InitObsData();
  29. obsPlayerPanel = this.transform.Find("ObsPlayerPanel").GetComponent<ObsPlayerPanel>();
  30. obsPlayerPanel.gameObject.SetActive(false);
  31. _obsSearchInputField.onValueChanged.AddListener(SearchObsItem);
  32. }
  33. private void OnDisable()
  34. {
  35. obsPlayerPanel.gameObject.SetActive(false);
  36. }
  37. private async Task InitObsData() {
  38. await new WaitUntil(() =>
  39. {
  40. return GlobalData.obsDatas_by.Count > 0&&GlobalData.obsDatas_tk.Count>0;
  41. });
  42. ObsData[] obs_by = GlobalData.obsDatas_by.ToArray();
  43. for (int i = 0; i < obs_by.Length; i++)
  44. {
  45. int tempIndex = i;
  46. SPJK_ObsItem tempItem = Instantiate(spjkItemOri, spjkItemContent).GetComponent<SPJK_ObsItem>();
  47. tempItem.SetData(obs_by[tempIndex]);
  48. currentObsDataList.Add(tempItem);
  49. tempItem.gameObject.GetComponent<Button>().onClick.AddListener(() =>
  50. {
  51. ShowObsPanel(obs_by[tempIndex]);
  52. });
  53. }
  54. ObsData[] obs_tk = GlobalData.obsDatas_tk.ToArray();
  55. for (int i = 0; i < obs_tk.Length; i++)
  56. {
  57. int tempIndex = i;
  58. SPJK_ObsItem tempItem = Instantiate(spjkItemOri, spjkItemContent).GetComponent<SPJK_ObsItem>();
  59. tempItem.SetData(obs_tk[tempIndex]);
  60. currentObsDataList.Add(tempItem);
  61. tempItem.gameObject.GetComponent<Button>().onClick.AddListener(() =>
  62. {
  63. ShowObsPanel(obs_tk[tempIndex]);
  64. });
  65. }
  66. countText.text = $"监控列表 (<color=#FFFFFF>{obs_by.Length+obs_tk.Length}</color>)";
  67. for (int i = 0; i < _obsIconCtrls.Count; i++)
  68. {
  69. Destroy(_obsIconCtrls[i].gameObject);
  70. }
  71. for (int i = 0; i < GlobalData.layerUnitDatas.Count; i++)
  72. {
  73. if (GlobalData.layerUnitDatas[i].type == LayerUnitType.JK)
  74. {
  75. if (GlobalData.layerUnitDatas[i].text1 == "补元退洪闸")
  76. {
  77. BYObsUseLib.Add(GlobalData.layerUnitDatas[i].namePri, false);
  78. }
  79. else if (GlobalData.layerUnitDatas[i].text1 == "套口进洪闸")
  80. {
  81. TKObsUseLib.Add(GlobalData.layerUnitDatas[i].namePri, false);
  82. }
  83. }
  84. }
  85. foreach (string keyName in BYObsUseLib.Keys)
  86. {
  87. if (!BYObsUseLib[keyName])
  88. {
  89. ObsIconCtrl tempIcon = Instantiate(obsIconPrefab, _obsIconContent).GetComponent<ObsIconCtrl>();
  90. ObsData errorObs = new ObsData();
  91. errorObs.name = keyName + "(丢失)";
  92. errorObs.targetName = keyName;
  93. errorObs.type = obsType.BuYuanObs;
  94. errorObs.status = false;
  95. tempIcon.Init(errorObs);
  96. _obsIconCtrls.Add(tempIcon);
  97. }
  98. }
  99. foreach (string keyName in TKObsUseLib.Keys)
  100. {
  101. if (!TKObsUseLib[keyName])
  102. {
  103. ObsIconCtrl tempIcon = Instantiate(obsIconPrefab, _obsIconContent).GetComponent<ObsIconCtrl>();
  104. ObsData errorObs = new ObsData();
  105. errorObs.name = keyName + "(丢失)";
  106. errorObs.targetName = keyName;
  107. errorObs.type = obsType.TaoKouObs;
  108. errorObs.status = false;
  109. tempIcon.Init(errorObs);
  110. _obsIconCtrls.Add(tempIcon);
  111. }
  112. }
  113. }
  114. public void SearchObsItem(string s_name)
  115. {
  116. if (s_name.Equals(""))
  117. {
  118. for (int i = 0; i < currentObsDataList.Count; i++)
  119. {
  120. currentObsDataList[i].gameObject.SetActive(true);
  121. }
  122. }
  123. else
  124. {
  125. for (int i = 0; i < currentObsDataList.Count; i++)
  126. {
  127. currentObsDataList[i].gameObject.SetActive(currentObsDataList[i]._data.name.Contains(s_name));
  128. }
  129. }
  130. }
  131. public void ShowObsPanel(ObsData _data)
  132. {
  133. obsPlayerPanel.gameObject.SetActive(true);
  134. obsPlayerPanel.SetObsData(_data);
  135. obsPlayerPanel.SetTitle(_data.name);
  136. }
  137. }