ZMJKLayer.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  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. public GameObject byThreeLine;
  34. public GameObject tkThreesLine;
  35. private void Awake()
  36. {
  37. closeButton.onClick.AddListener(() =>
  38. {
  39. gongChengPanel.SetActive(false);
  40. showGongPanel = false;
  41. });
  42. gongChengPanel.SetActive(false);
  43. showGongPanel = false;
  44. }
  45. private void OnEnable()
  46. {
  47. _camera = CameraManager.instance.mainCamera;
  48. StaticLod.instance.OnFoucusStatic(0);
  49. }
  50. // Start is called before the first frame update
  51. async void Start()
  52. {
  53. InitFloorGateData();
  54. _zmSearchInputField.onValueChanged.AddListener(SearchObsItem);
  55. byBtn.onClick.AddListener(() =>
  56. {
  57. byBtn.GetComponent<CanvasGroup>().alpha = 1;
  58. tkBtn.GetComponent<CanvasGroup>().alpha = 0.5f;
  59. StaticLod.instance.OnFoucusStatic("BuYuan");
  60. });
  61. tkBtn.onClick.AddListener(() =>
  62. {
  63. byBtn.GetComponent<CanvasGroup>().alpha = 0.5f;
  64. tkBtn.GetComponent<CanvasGroup>().alpha = 1f;
  65. StaticLod.instance.OnFoucusStatic("TaoKou");
  66. });
  67. }
  68. async Task InitFloorGateData()
  69. {
  70. await new WaitUntil(() => { return GlobalData.floorGateData.success; });
  71. float[] byV3 = new float[GlobalData.floorGateData.buYuan.Length];
  72. for (int i = 0; i < GlobalData.floorGateData.buYuan.Length; i++)
  73. {
  74. int tempIndex = i;
  75. ZhaZhanItem tempItem = Instantiate(ZhaZhanItemOri, itemContent).GetComponent<ZhaZhanItem>();
  76. tempItem.SetData(GlobalData.floorGateData.buYuan[tempIndex], $"补元-{tempIndex + 1}#闸门");
  77. byV3[tempIndex] = GlobalData.floorGateData.buYuan[tempIndex].opening_degree;
  78. //Debug.Log($"补元闸门-{tempIndex + 1}:{byV3[tempIndex]}");
  79. tempItem.gameObject.GetComponent<Button>().onClick.AddListener(() =>
  80. {
  81. OpenZhaMenInfoPanel(0, tempIndex, tempItem);
  82. });
  83. currentZMDataList.Add(tempItem);
  84. ZhaMenIconCtrl tempIcon = Instantiate(zhaMenIconOri, zhaMenContent).GetComponent<ZhaMenIconCtrl>();
  85. tempIcon.Init(GlobalData.floorGateData.buYuan[tempIndex], $"补元:-{tempIndex + 1}#闸门",
  86. StaticLod.instance.GetStaticObj($"BY_ZM_{tempIndex + 1:00}"),
  87. () =>
  88. {
  89. OpenZhaMenInfoPanel(0, tempIndex, tempItem);
  90. });
  91. zhaMenIconList.Add(tempIcon);
  92. }
  93. ActionInstance._Instance.ModelAni_On?.Invoke(AniType.buYuan, byV3);
  94. float[] tkV3 = new float[GlobalData.floorGateData.taoKou.Length];
  95. for (int i = 0; i < GlobalData.floorGateData.taoKou.Length; i++)
  96. {
  97. int tempIndex = i;
  98. ZhaZhanItem tempItem = Instantiate(ZhaZhanItemOri, itemContent).GetComponent<ZhaZhanItem>();
  99. tempItem.SetData(GlobalData.floorGateData.taoKou[tempIndex], $"套口:{tempIndex + 1}#闸门");
  100. tkV3[tempIndex] = GlobalData.floorGateData.taoKou[tempIndex].opening_degree;
  101. tempItem.gameObject.GetComponent<Button>().onClick.AddListener(() =>
  102. {
  103. OpenZhaMenInfoPanel(1, tempIndex, tempItem);
  104. });
  105. currentZMDataList.Add(tempItem);
  106. ZhaMenIconCtrl tempIcon = Instantiate(zhaMenIconOri, zhaMenContent).GetComponent<ZhaMenIconCtrl>();
  107. tempIcon.Init(GlobalData.floorGateData.taoKou[tempIndex], $"套口:-{tempIndex + 1}#闸门",
  108. StaticLod.instance.GetStaticObj($"TK_ZM_{tempIndex + 1:00}"), () =>
  109. {
  110. OpenZhaMenInfoPanel(1, tempIndex, tempItem);
  111. });
  112. zhaMenIconList.Add(tempIcon);
  113. }
  114. ActionInstance._Instance.ModelAni_On?.Invoke(AniType.taoKou, tkV3);
  115. int totalCount = GlobalData.floorGateData.BuYuanTotalGates + GlobalData.floorGateData.TaoKouTotalGates;
  116. zhaZhanCount.text = $"闸门列表 (<color=#FFFFFF>{totalCount}</color>)";
  117. }
  118. public void OpenZhaMenInfoPanel(int type, int _index, ZhaZhanItem itemData)
  119. {
  120. string staticNameHead = type == 0 ? "BY_ZM_" : "TK_ZM_";
  121. StaticLod.instance.OnFoucusStatic($"{staticNameHead}{_index + 1:00}");
  122. targetObj = StaticLod.instance.GetStaticObj($"{staticNameHead}{_index + 1:00}");
  123. gongChengPanel.SetActive(true);
  124. showGongPanel = true;
  125. zhaZhanMingCheng.text = itemData._name;
  126. var floorGateData = type == 0 ? GlobalData.floorGateData.buYuan : GlobalData.floorGateData.taoKou;
  127. zhaMenKaiDu.text = $"{floorGateData[_index].opening_degree:0.00}<size=14><color=#A5BFE2>m</color></size>";
  128. guoZhaLiuLiang.text = $"-<size=14><color=#A5BFE2>m\u00b3/s</color></size>";
  129. if (type == 0)
  130. {
  131. string swUp = null;
  132. string swDown = null;
  133. string swUpName = "";
  134. string swDownName = "";
  135. for (int i = 0; i < GlobalData.swDatas.Count; i++)
  136. {
  137. if (GlobalData.swDatas[i].stnm == "补元(闸上)")
  138. {
  139. swUp = GlobalData.swDatas[i].upz;
  140. swUpName = GlobalData.swDatas[i].stnm;
  141. }
  142. if (GlobalData.swDatas[i].stnm == "补元(闸下)")
  143. {
  144. swDown = GlobalData.swDatas[i].dwz;
  145. swDownName = GlobalData.swDatas[i].stnm;
  146. }
  147. }
  148. zhaQianShuiWei.text = swUp == null ? $"- <size=14><color=#A5BFE2>m</color></size>" : $"{swUp} <size=14><color=#A5BFE2>m</color></size>";
  149. zhaHouShuiWei.text = swDown == null ? $"- <size=14><color=#A5BFE2>m</color></size>" : $"{swDown} <size=14><color=#A5BFE2>m</color></size>";
  150. }
  151. else
  152. {
  153. string swUp = null;
  154. string swDown =null;
  155. string swUpName="";
  156. string swDownName="";
  157. for (int i = 0; i < GlobalData.swDatas.Count; i++)
  158. {
  159. if (GlobalData.swDatas[i].stnm == "套口(闸上)")
  160. {
  161. swUp = GlobalData.swDatas[i].upz;
  162. swUpName = GlobalData.swDatas[i].stnm;
  163. }
  164. if (GlobalData.swDatas[i].stnm == "套口(闸下)")
  165. {
  166. swDown = GlobalData.swDatas[i].dwz;
  167. swDownName = GlobalData.swDatas[i].stnm;
  168. }
  169. }
  170. zhaQianShuiWei.text = swUp == null ? $"- <size=14><color=#A5BFE2>m</color></size>" : $"{swUp} <size=14><color=#A5BFE2>m</color></size>";
  171. zhaHouShuiWei.text = swDown == null ? $"- <size=14><color=#A5BFE2>m</color></size>" : $"{swDown} <size=14><color=#A5BFE2>m</color></size>";
  172. }
  173. //for (int i = 0; i < GlobalData.swDatas.Count; i++)
  174. //{
  175. // Debug.Log("111111111111:" + GlobalData.swDatas[i].stnm);
  176. // Debug.Log("111111111111:" + GlobalData.swDatas[i].upz);
  177. // Debug.Log("111111111111:" + GlobalData.swDatas[i].dwz);
  178. //}
  179. var shuiweiData = type == 0 ? GlobalData.floorGateData.swzxtBY : GlobalData.floorGateData.swzxtTK;
  180. var finalData = new CharData_water[shuiweiData.Length];
  181. for (int i = 0; i < shuiweiData.Length; i++)
  182. {
  183. finalData[i] = shuiweiData[shuiweiData.Length - 1 - i];
  184. }
  185. XAxis tempXaxis = shuiweiChart.GetChartComponent<XAxis>();
  186. tempXaxis.data.Clear();
  187. for (int i = 0; i < finalData.Length; i++)
  188. {
  189. tempXaxis.AddData(finalData[i].key);
  190. }
  191. var tempSeries = shuiweiChart.series;
  192. tempSeries[0].serieName = "水位/m";
  193. SerieData[] tempDatas = new SerieData[finalData.Length];
  194. for (int i = 0; i < tempDatas.Length; i++)
  195. {
  196. tempDatas[i] = new SerieData();
  197. tempDatas[i].data = new List<double>();
  198. tempDatas[i].data.Add(i);
  199. string value = finalData[i].value;
  200. if (finalData[i].value == "-") {
  201. value = "-1";
  202. }
  203. tempDatas[i].data.Add(float.Parse(value));
  204. }
  205. tempSeries[0].data.Clear();
  206. tempSeries[0].data.AddRange(tempDatas);
  207. if (type == 0)
  208. {
  209. byThreeLine.gameObject.SetActive(true);
  210. tkThreesLine.gameObject.SetActive(false);
  211. }
  212. else
  213. {
  214. byThreeLine.gameObject.SetActive(false);
  215. tkThreesLine.gameObject.SetActive(true);
  216. }
  217. }
  218. public void SearchObsItem(string s_name)
  219. {
  220. if (s_name.Equals(""))
  221. {
  222. for (int i = 0; i < currentZMDataList.Count; i++)
  223. {
  224. currentZMDataList[i].gameObject.SetActive(true);
  225. }
  226. }
  227. else
  228. {
  229. for (int i = 0; i < currentZMDataList.Count; i++)
  230. {
  231. currentZMDataList[i].gameObject.SetActive(currentZMDataList[i]._name.Contains(s_name));
  232. }
  233. }
  234. }
  235. // Update is called once per frame
  236. void Update()
  237. {
  238. if (showGongPanel)
  239. {
  240. if (targetObj != null)
  241. {
  242. if (IsObjectInCameraView(targetObj.transform, _camera))
  243. {
  244. gongChengPanel.transform.position = _camera.WorldToScreenPoint(targetObj.transform.position);
  245. }
  246. }
  247. }
  248. }
  249. bool IsObjectInCameraView(Transform objectTransform, Camera camera)
  250. {
  251. Vector3 objectScreenPosition = camera.WorldToScreenPoint(objectTransform.position);
  252. return objectScreenPosition.z > 0 &&
  253. objectScreenPosition.x > 0 &&
  254. objectScreenPosition.x < Screen.width &&
  255. objectScreenPosition.y > 0 &&
  256. objectScreenPosition.y < Screen.height;
  257. }
  258. }