ZMJKLayer.cs 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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. //for (int i = 0; i < GlobalData.swDatas.Count; i++)
  124. //{
  125. // Debug.Log("111111111111:" + GlobalData.swDatas[i].stnm);
  126. // Debug.Log("111111111111:" + GlobalData.swDatas[i].upz);
  127. // Debug.Log("111111111111:" + GlobalData.swDatas[i].dwz);
  128. //}
  129. var shuiweiData = type == 0 ? GlobalData.floorGateData.swzxtBY : GlobalData.floorGateData.swzxtTK;
  130. XAxis tempXaxis = shuiweiChart.GetChartComponent<XAxis>();
  131. tempXaxis.data.Clear();
  132. for (int i = 0; i < shuiweiData.Length; i++)
  133. {
  134. tempXaxis.AddData(shuiweiData[i].key);
  135. }
  136. var tempSeries = shuiweiChart.series;
  137. tempSeries[0].serieName = "水位";
  138. tempSeries[1].serieName = "水位";
  139. SerieData[] tempDatas = new SerieData[shuiweiData.Length];
  140. for (int i = 0; i < tempDatas.Length; i++)
  141. {
  142. tempDatas[i] = new SerieData();
  143. tempDatas[i].data = new List<double>();
  144. tempDatas[i].data.Add(i);
  145. string value = shuiweiData[i].value;
  146. if (shuiweiData[i].value == "-") {
  147. value = "-1";
  148. }
  149. tempDatas[i].data.Add(float.Parse(value));
  150. }
  151. tempSeries[0].data.Clear();
  152. tempSeries[0].data.AddRange(tempDatas);
  153. tempSeries[1].data.Clear();
  154. tempSeries[1].data.AddRange(tempDatas);
  155. }
  156. public void SearchObsItem(string s_name)
  157. {
  158. if (s_name.Equals(""))
  159. {
  160. for (int i = 0; i < currentZMDataList.Count; i++)
  161. {
  162. currentZMDataList[i].gameObject.SetActive(true);
  163. }
  164. }
  165. else
  166. {
  167. for (int i = 0; i < currentZMDataList.Count; i++)
  168. {
  169. currentZMDataList[i].gameObject.SetActive(currentZMDataList[i]._name.Contains(s_name));
  170. }
  171. }
  172. }
  173. // Update is called once per frame
  174. void Update()
  175. {
  176. if (showGongPanel)
  177. {
  178. if (targetObj != null)
  179. {
  180. if (IsObjectInCameraView(targetObj.transform, _camera))
  181. {
  182. gongChengPanel.transform.position = _camera.WorldToScreenPoint(targetObj.transform.position);
  183. }
  184. }
  185. }
  186. }
  187. bool IsObjectInCameraView(Transform objectTransform, Camera camera)
  188. {
  189. Vector3 objectScreenPosition = camera.WorldToScreenPoint(objectTransform.position);
  190. return objectScreenPosition.z > 0 &&
  191. objectScreenPosition.x > 0 &&
  192. objectScreenPosition.x < Screen.width &&
  193. objectScreenPosition.y > 0 &&
  194. objectScreenPosition.y < Screen.height;
  195. }
  196. }