ZMJKLayer.cs 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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. using XCharts.Runtime;
  10. public class ZMJKLayer : MonoBehaviour
  11. {
  12. public GameObject ZhaZhanItemOri;
  13. public Transform itemContent;
  14. public Text zhaZhanCount;
  15. public GameObject gongChengPanel;
  16. public Button closeButton;
  17. public Text zhaZhanMingCheng;
  18. public Text zhaQianShuiWei;
  19. public Text zhaHouShuiWei;
  20. public Text zhaMenKaiDu;
  21. public Text guoZhaLiuLiang;
  22. public Button byBtn;
  23. public Button tkBtn;
  24. public BarChart shuiweiChart;
  25. public InputField _zmSearchInputField;
  26. public List<ZhaZhanItem> currentZMDataList = new List<ZhaZhanItem>();
  27. public GameObject targetObj;
  28. public bool showGongPanel = false;
  29. private Camera _camera;
  30. public GameObject zhaMenIconOri;
  31. public Transform zhaMenContent;
  32. public List<ZhaMenIconCtrl> zhaMenIconList = new List<ZhaMenIconCtrl>();
  33. private void Awake()
  34. {
  35. closeButton.onClick.AddListener(() =>
  36. {
  37. gongChengPanel.SetActive(false);
  38. showGongPanel = false;
  39. });
  40. gongChengPanel.SetActive(false);
  41. showGongPanel = false;
  42. }
  43. private void OnEnable()
  44. {
  45. _camera = CameraManager.instance.mainCamera;
  46. StaticLod.instance.OnFoucusStatic(0);
  47. }
  48. // Start is called before the first frame update
  49. async void Start()
  50. {
  51. InitFloorGateData();
  52. _zmSearchInputField.onValueChanged.AddListener(SearchObsItem);
  53. byBtn.onClick.AddListener(() =>
  54. {
  55. byBtn.GetComponent<CanvasGroup>().alpha = 1;
  56. tkBtn.GetComponent<CanvasGroup>().alpha = 0.5f;
  57. StaticLod.instance.OnFoucusStatic("BuYuan");
  58. });
  59. tkBtn.onClick.AddListener(() =>
  60. {
  61. byBtn.GetComponent<CanvasGroup>().alpha = 0.5f;
  62. tkBtn.GetComponent<CanvasGroup>().alpha = 1f;
  63. StaticLod.instance.OnFoucusStatic("TaoKou");
  64. });
  65. }
  66. async Task InitFloorGateData()
  67. {
  68. await new WaitUntil(() => { return GlobalData.floorGateData.success; });
  69. float[] byV3 = new float[GlobalData.floorGateData.buYuan.Length];
  70. for (int i = 0; i < GlobalData.floorGateData.buYuan.Length; i++)
  71. {
  72. int tempIndex = i;
  73. ZhaZhanItem tempItem = Instantiate(ZhaZhanItemOri, itemContent).GetComponent<ZhaZhanItem>();
  74. tempItem.SetData(GlobalData.floorGateData.buYuan[tempIndex], $"补元闸门-{tempIndex + 1}");
  75. byV3[tempIndex] = GlobalData.floorGateData.buYuan[tempIndex].opening_degree * 0.01f;
  76. //Debug.Log($"补元闸门-{tempIndex + 1}:{byV3[tempIndex]}");
  77. tempItem.gameObject.GetComponent<Button>().onClick.AddListener(() =>
  78. {
  79. OpenZhaMenInfoPanel(0, tempIndex, tempItem);
  80. });
  81. currentZMDataList.Add(tempItem);
  82. ZhaMenIconCtrl tempIcon = Instantiate(zhaMenIconOri, zhaMenContent).GetComponent<ZhaMenIconCtrl>();
  83. tempIcon.Init(GlobalData.floorGateData.buYuan[tempIndex], $"补元闸门-{tempIndex + 1}",
  84. StaticLod.instance.GetStaticObj($"BY_ZM_{tempIndex + 1:00}"));
  85. zhaMenIconList.Add(tempIcon);
  86. }
  87. ActionInstance._Instance.ModelAni_On?.Invoke(AniType.buYuan, byV3);
  88. float[] tkV3 = new float[GlobalData.floorGateData.taoKou.Length];
  89. for (int i = 0; i < GlobalData.floorGateData.taoKou.Length; i++)
  90. {
  91. int tempIndex = i;
  92. ZhaZhanItem tempItem = Instantiate(ZhaZhanItemOri, itemContent).GetComponent<ZhaZhanItem>();
  93. tempItem.SetData(GlobalData.floorGateData.taoKou[tempIndex], $"套口闸门-{tempIndex + 1}");
  94. tkV3[tempIndex] = GlobalData.floorGateData.taoKou[tempIndex].opening_degree * 0.01f;
  95. tempItem.gameObject.GetComponent<Button>().onClick.AddListener(() =>
  96. {
  97. OpenZhaMenInfoPanel(1, tempIndex, tempItem);
  98. });
  99. currentZMDataList.Add(tempItem);
  100. ZhaMenIconCtrl tempIcon = Instantiate(zhaMenIconOri, zhaMenContent).GetComponent<ZhaMenIconCtrl>();
  101. tempIcon.Init(GlobalData.floorGateData.taoKou[tempIndex], $"套口闸门-{tempIndex + 1}",
  102. StaticLod.instance.GetStaticObj($"TK_ZM_{tempIndex + 1:00}"));
  103. zhaMenIconList.Add(tempIcon);
  104. }
  105. ActionInstance._Instance.ModelAni_On?.Invoke(AniType.taoKou, tkV3);
  106. int totalCount = GlobalData.floorGateData.BuYuanTotalGates + GlobalData.floorGateData.TaoKouTotalGates;
  107. zhaZhanCount.text = $"闸门列表 (<color=#FFFFFF>{totalCount}</color>)";
  108. }
  109. public void OpenZhaMenInfoPanel(int type, int _index, ZhaZhanItem itemData)
  110. {
  111. string staticNameHead = type == 0 ? "BY_ZM_" : "TK_ZM_";
  112. StaticLod.instance.OnFoucusStatic($"{staticNameHead}{_index + 1:00}");
  113. targetObj = StaticLod.instance.GetStaticObj($"{staticNameHead}{_index + 1:00}");
  114. gongChengPanel.SetActive(true);
  115. showGongPanel = true;
  116. zhaZhanMingCheng.text = itemData._name;
  117. var floorGateData = type == 0 ? GlobalData.floorGateData.buYuan : GlobalData.floorGateData.taoKou;
  118. zhaMenKaiDu.text = $"{floorGateData[_index].opening_degree:0.00}<size=14><color=#A5BFE2>%</color></size>";
  119. guoZhaLiuLiang.text = $"-<size=14><color=#A5BFE2>m\u00b3/s</color></size>";
  120. zhaQianShuiWei.text = $"- <size=14><color=#A5BFE2>m</color></size>";
  121. var floorGateData_sw = type == 0 ? GlobalData.floorGateData.buYuanSW : GlobalData.floorGateData.taoKouSW;
  122. zhaHouShuiWei.text = $"{floorGateData_sw} <size=14><color=#A5BFE2>m</color></size>";
  123. var shuiweiData = type == 0 ? GlobalData.floorGateData.swzxtBY : GlobalData.floorGateData.swzxtTK;
  124. XAxis tempXaxis = shuiweiChart.GetChartComponent<XAxis>();
  125. tempXaxis.data.Clear();
  126. for (int i = 0; i < shuiweiData.Length; i++)
  127. {
  128. tempXaxis.AddData(shuiweiData[i].key);
  129. }
  130. var tempSeries = shuiweiChart.series;
  131. tempSeries[0].serieName = "水位";
  132. tempSeries[1].serieName = "水位";
  133. SerieData[] tempDatas = new SerieData[shuiweiData.Length];
  134. for (int i = 0; i < tempDatas.Length; i++)
  135. {
  136. tempDatas[i] = new SerieData();
  137. tempDatas[i].data = new List<double>();
  138. tempDatas[i].data.Add(i);
  139. tempDatas[i].data.Add(shuiweiData[i].value);
  140. }
  141. tempSeries[0].data.Clear();
  142. tempSeries[0].data.AddRange(tempDatas);
  143. tempSeries[1].data.Clear();
  144. tempSeries[1].data.AddRange(tempDatas);
  145. }
  146. public void SearchObsItem(string s_name)
  147. {
  148. if (s_name.Equals(""))
  149. {
  150. for (int i = 0; i < currentZMDataList.Count; i++)
  151. {
  152. currentZMDataList[i].gameObject.SetActive(true);
  153. }
  154. }
  155. else
  156. {
  157. for (int i = 0; i < currentZMDataList.Count; i++)
  158. {
  159. currentZMDataList[i].gameObject.SetActive(currentZMDataList[i]._name.Contains(s_name));
  160. }
  161. }
  162. }
  163. // Update is called once per frame
  164. void Update()
  165. {
  166. if (showGongPanel)
  167. {
  168. if (targetObj != null)
  169. {
  170. if (IsObjectInCameraView(targetObj.transform, _camera))
  171. {
  172. gongChengPanel.transform.position = _camera.WorldToScreenPoint(targetObj.transform.position);
  173. }
  174. }
  175. }
  176. }
  177. bool IsObjectInCameraView(Transform objectTransform, Camera camera)
  178. {
  179. Vector3 objectScreenPosition = camera.WorldToScreenPoint(objectTransform.position);
  180. return objectScreenPosition.z > 0 &&
  181. objectScreenPosition.x > 0 &&
  182. objectScreenPosition.x < Screen.width &&
  183. objectScreenPosition.y > 0 &&
  184. objectScreenPosition.y < Screen.height;
  185. }
  186. }