ZMJKLayer.cs 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  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. if (type == 0)
  121. {
  122. float? swUp = null;
  123. float? swDown = null;
  124. string swUpName = "";
  125. string swDownName = "";
  126. for (int i = 0; i < GlobalData.swDatas.Count; i++)
  127. {
  128. if (GlobalData.swDatas[i].stnm == "补元(闸上)")
  129. {
  130. swUp = GlobalData.swDatas[i].upz;
  131. swUpName = GlobalData.swDatas[i].stnm;
  132. }
  133. if (GlobalData.swDatas[i].stnm == "补元(闸下)")
  134. {
  135. swDown = GlobalData.swDatas[i].dwz;
  136. swDownName = GlobalData.swDatas[i].stnm;
  137. }
  138. }
  139. zhaQianShuiWei.text = swUp == null ? $"- <size=14><color=#A5BFE2>m</color></size>" : $"{swUp} <size=14><color=#A5BFE2>m</color></size>";
  140. zhaHouShuiWei.text = swDown == null ? $"- <size=14><color=#A5BFE2>m</color></size>" : $"{swDown} <size=14><color=#A5BFE2>m</color></size>";
  141. }
  142. else
  143. {
  144. float? swUp = null;
  145. float? swDown=null;
  146. string swUpName="";
  147. string swDownName="";
  148. for (int i = 0; i < GlobalData.swDatas.Count; i++)
  149. {
  150. if (GlobalData.swDatas[i].stnm == "套口(闸上)")
  151. {
  152. swUp = GlobalData.swDatas[i].upz;
  153. swUpName = GlobalData.swDatas[i].stnm;
  154. }
  155. if (GlobalData.swDatas[i].stnm == "套口(闸下)")
  156. {
  157. swDown = GlobalData.swDatas[i].dwz;
  158. swDownName = GlobalData.swDatas[i].stnm;
  159. }
  160. }
  161. zhaQianShuiWei.text = swUp == null ? $"- <size=14><color=#A5BFE2>m</color></size>" : $"{swUp} <size=14><color=#A5BFE2>m</color></size>";
  162. zhaHouShuiWei.text = swDown == null ? $"- <size=14><color=#A5BFE2>m</color></size>" : $"{swDown} <size=14><color=#A5BFE2>m</color></size>";
  163. }
  164. //for (int i = 0; i < GlobalData.swDatas.Count; i++)
  165. //{
  166. // Debug.Log("111111111111:" + GlobalData.swDatas[i].stnm);
  167. // Debug.Log("111111111111:" + GlobalData.swDatas[i].upz);
  168. // Debug.Log("111111111111:" + GlobalData.swDatas[i].dwz);
  169. //}
  170. var shuiweiData = type == 0 ? GlobalData.floorGateData.swzxtBY : GlobalData.floorGateData.swzxtTK;
  171. XAxis tempXaxis = shuiweiChart.GetChartComponent<XAxis>();
  172. tempXaxis.data.Clear();
  173. for (int i = 0; i < shuiweiData.Length; i++)
  174. {
  175. tempXaxis.AddData(shuiweiData[i].key);
  176. }
  177. var tempSeries = shuiweiChart.series;
  178. tempSeries[0].serieName = "水位";
  179. SerieData[] tempDatas = new SerieData[shuiweiData.Length];
  180. for (int i = 0; i < tempDatas.Length; i++)
  181. {
  182. tempDatas[i] = new SerieData();
  183. tempDatas[i].data = new List<double>();
  184. tempDatas[i].data.Add(i);
  185. string value = shuiweiData[i].value;
  186. if (shuiweiData[i].value == "-") {
  187. value = "-1";
  188. }
  189. tempDatas[i].data.Add(float.Parse(value));
  190. }
  191. tempSeries[0].data.Clear();
  192. tempSeries[0].data.AddRange(tempDatas);
  193. }
  194. public void SearchObsItem(string s_name)
  195. {
  196. if (s_name.Equals(""))
  197. {
  198. for (int i = 0; i < currentZMDataList.Count; i++)
  199. {
  200. currentZMDataList[i].gameObject.SetActive(true);
  201. }
  202. }
  203. else
  204. {
  205. for (int i = 0; i < currentZMDataList.Count; i++)
  206. {
  207. currentZMDataList[i].gameObject.SetActive(currentZMDataList[i]._name.Contains(s_name));
  208. }
  209. }
  210. }
  211. // Update is called once per frame
  212. void Update()
  213. {
  214. if (showGongPanel)
  215. {
  216. if (targetObj != null)
  217. {
  218. if (IsObjectInCameraView(targetObj.transform, _camera))
  219. {
  220. gongChengPanel.transform.position = _camera.WorldToScreenPoint(targetObj.transform.position);
  221. }
  222. }
  223. }
  224. }
  225. bool IsObjectInCameraView(Transform objectTransform, Camera camera)
  226. {
  227. Vector3 objectScreenPosition = camera.WorldToScreenPoint(objectTransform.position);
  228. return objectScreenPosition.z > 0 &&
  229. objectScreenPosition.x > 0 &&
  230. objectScreenPosition.x < Screen.width &&
  231. objectScreenPosition.y > 0 &&
  232. objectScreenPosition.y < Screen.height;
  233. }
  234. }