ZMJKLayer.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  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;
  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. () =>
  86. {
  87. OpenZhaMenInfoPanel(0, tempIndex, tempItem);
  88. });
  89. zhaMenIconList.Add(tempIcon);
  90. }
  91. ActionInstance._Instance.ModelAni_On?.Invoke(AniType.buYuan, byV3);
  92. float[] tkV3 = new float[GlobalData.floorGateData.taoKou.Length];
  93. for (int i = 0; i < GlobalData.floorGateData.taoKou.Length; i++)
  94. {
  95. int tempIndex = i;
  96. ZhaZhanItem tempItem = Instantiate(ZhaZhanItemOri, itemContent).GetComponent<ZhaZhanItem>();
  97. tempItem.SetData(GlobalData.floorGateData.taoKou[tempIndex], $"套口:{tempIndex + 1}#闸门");
  98. tkV3[tempIndex] = GlobalData.floorGateData.taoKou[tempIndex].opening_degree;
  99. tempItem.gameObject.GetComponent<Button>().onClick.AddListener(() =>
  100. {
  101. OpenZhaMenInfoPanel(1, tempIndex, tempItem);
  102. });
  103. currentZMDataList.Add(tempItem);
  104. ZhaMenIconCtrl tempIcon = Instantiate(zhaMenIconOri, zhaMenContent).GetComponent<ZhaMenIconCtrl>();
  105. tempIcon.Init(GlobalData.floorGateData.taoKou[tempIndex], $"套口:-{tempIndex + 1}#闸门",
  106. StaticLod.instance.GetStaticObj($"TK_ZM_{tempIndex + 1:00}"), () =>
  107. {
  108. OpenZhaMenInfoPanel(1, tempIndex, tempItem);
  109. });
  110. zhaMenIconList.Add(tempIcon);
  111. }
  112. ActionInstance._Instance.ModelAni_On?.Invoke(AniType.taoKou, tkV3);
  113. int totalCount = GlobalData.floorGateData.BuYuanTotalGates + GlobalData.floorGateData.TaoKouTotalGates;
  114. zhaZhanCount.text = $"闸门列表 (<color=#FFFFFF>{totalCount}</color>)";
  115. }
  116. public void OpenZhaMenInfoPanel(int type, int _index, ZhaZhanItem itemData)
  117. {
  118. string staticNameHead = type == 0 ? "BY_ZM_" : "TK_ZM_";
  119. StaticLod.instance.OnFoucusStatic($"{staticNameHead}{_index + 1:00}");
  120. targetObj = StaticLod.instance.GetStaticObj($"{staticNameHead}{_index + 1:00}");
  121. gongChengPanel.SetActive(true);
  122. showGongPanel = true;
  123. zhaZhanMingCheng.text = itemData._name;
  124. var floorGateData = type == 0 ? GlobalData.floorGateData.buYuan : GlobalData.floorGateData.taoKou;
  125. zhaMenKaiDu.text = $"{floorGateData[_index].opening_degree:0.00}<size=14><color=#A5BFE2>m</color></size>";
  126. guoZhaLiuLiang.text = $"-<size=14><color=#A5BFE2>m\u00b3/s</color></size>";
  127. if (type == 0)
  128. {
  129. string swUp = null;
  130. string swDown = null;
  131. string swUpName = "";
  132. string swDownName = "";
  133. for (int i = 0; i < GlobalData.swDatas.Count; i++)
  134. {
  135. if (GlobalData.swDatas[i].stnm == "补元(闸上)")
  136. {
  137. swUp = GlobalData.swDatas[i].upz;
  138. swUpName = GlobalData.swDatas[i].stnm;
  139. }
  140. if (GlobalData.swDatas[i].stnm == "补元(闸下)")
  141. {
  142. swDown = GlobalData.swDatas[i].dwz;
  143. swDownName = GlobalData.swDatas[i].stnm;
  144. }
  145. }
  146. zhaQianShuiWei.text = swUp == null ? $"- <size=14><color=#A5BFE2>m</color></size>" : $"{swUp} <size=14><color=#A5BFE2>m</color></size>";
  147. zhaHouShuiWei.text = swDown == null ? $"- <size=14><color=#A5BFE2>m</color></size>" : $"{swDown} <size=14><color=#A5BFE2>m</color></size>";
  148. }
  149. else
  150. {
  151. string swUp = null;
  152. string swDown =null;
  153. string swUpName="";
  154. string swDownName="";
  155. for (int i = 0; i < GlobalData.swDatas.Count; i++)
  156. {
  157. if (GlobalData.swDatas[i].stnm == "套口(闸上)")
  158. {
  159. swUp = GlobalData.swDatas[i].upz;
  160. swUpName = GlobalData.swDatas[i].stnm;
  161. }
  162. if (GlobalData.swDatas[i].stnm == "套口(闸下)")
  163. {
  164. swDown = GlobalData.swDatas[i].dwz;
  165. swDownName = GlobalData.swDatas[i].stnm;
  166. }
  167. }
  168. zhaQianShuiWei.text = swUp == null ? $"- <size=14><color=#A5BFE2>m</color></size>" : $"{swUp} <size=14><color=#A5BFE2>m</color></size>";
  169. zhaHouShuiWei.text = swDown == null ? $"- <size=14><color=#A5BFE2>m</color></size>" : $"{swDown} <size=14><color=#A5BFE2>m</color></size>";
  170. }
  171. //for (int i = 0; i < GlobalData.swDatas.Count; i++)
  172. //{
  173. // Debug.Log("111111111111:" + GlobalData.swDatas[i].stnm);
  174. // Debug.Log("111111111111:" + GlobalData.swDatas[i].upz);
  175. // Debug.Log("111111111111:" + GlobalData.swDatas[i].dwz);
  176. //}
  177. var shuiweiData = type == 0 ? GlobalData.floorGateData.swzxtBY : GlobalData.floorGateData.swzxtTK;
  178. XAxis tempXaxis = shuiweiChart.GetChartComponent<XAxis>();
  179. tempXaxis.data.Clear();
  180. for (int i = 0; i < shuiweiData.Length; i++)
  181. {
  182. tempXaxis.AddData(shuiweiData[i].key);
  183. }
  184. var tempSeries = shuiweiChart.series;
  185. tempSeries[0].serieName = "水位";
  186. SerieData[] tempDatas = new SerieData[shuiweiData.Length];
  187. for (int i = 0; i < tempDatas.Length; i++)
  188. {
  189. tempDatas[i] = new SerieData();
  190. tempDatas[i].data = new List<double>();
  191. tempDatas[i].data.Add(i);
  192. string value = shuiweiData[i].value;
  193. if (shuiweiData[i].value == "-") {
  194. value = "-1";
  195. }
  196. tempDatas[i].data.Add(float.Parse(value));
  197. }
  198. tempSeries[0].data.Clear();
  199. tempSeries[0].data.AddRange(tempDatas);
  200. }
  201. public void SearchObsItem(string s_name)
  202. {
  203. if (s_name.Equals(""))
  204. {
  205. for (int i = 0; i < currentZMDataList.Count; i++)
  206. {
  207. currentZMDataList[i].gameObject.SetActive(true);
  208. }
  209. }
  210. else
  211. {
  212. for (int i = 0; i < currentZMDataList.Count; i++)
  213. {
  214. currentZMDataList[i].gameObject.SetActive(currentZMDataList[i]._name.Contains(s_name));
  215. }
  216. }
  217. }
  218. // Update is called once per frame
  219. void Update()
  220. {
  221. if (showGongPanel)
  222. {
  223. if (targetObj != null)
  224. {
  225. if (IsObjectInCameraView(targetObj.transform, _camera))
  226. {
  227. gongChengPanel.transform.position = _camera.WorldToScreenPoint(targetObj.transform.position);
  228. }
  229. }
  230. }
  231. }
  232. bool IsObjectInCameraView(Transform objectTransform, Camera camera)
  233. {
  234. Vector3 objectScreenPosition = camera.WorldToScreenPoint(objectTransform.position);
  235. return objectScreenPosition.z > 0 &&
  236. objectScreenPosition.x > 0 &&
  237. objectScreenPosition.x < Screen.width &&
  238. objectScreenPosition.y > 0 &&
  239. objectScreenPosition.y < Screen.height;
  240. }
  241. }