XHDDLayer.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533
  1. using DG.Tweening;
  2. using System;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using System.Threading.Tasks;
  6. using UnityAsync;
  7. using UnityEngine;
  8. using UnityEngine.UI;
  9. using WaitUntil = UnityAsync.WaitUntil;
  10. [System.Serializable]
  11. public enum YJType
  12. {
  13. YELLOW,
  14. ORANGE,
  15. RED
  16. }
  17. [Serializable]
  18. public class SchedulingPlan
  19. {
  20. public float max_water_level;
  21. public string max_water_level_unit;
  22. public string max_water_level_time;
  23. public float flood_peak_flow_rate;
  24. public string flood_peak_flow_rate_unit;
  25. public float intercepted_flood_volume;
  26. public string intercepted_flood_volume_unit;
  27. public int peak_reduction_rate;
  28. public float final_water_level;
  29. public string final_water_level_unit;
  30. }
  31. [Serializable]
  32. public class SchedulingResults
  33. {
  34. public float inflow_peak;
  35. public string inflow_peak_unit;
  36. public float outflow_total;
  37. public string outflow_total_unit;
  38. public float initial_water_level;
  39. public string initial_water_level_unit;
  40. public float target_water_level;
  41. public string target_water_level_unit;
  42. }
  43. [Serializable]
  44. public class RiskInformation
  45. {
  46. public string warning_level;
  47. public float submerged_area;
  48. public string submerged_area_unit;
  49. public float submerged_farmland_area;
  50. public string submerged_farmland_area_unit;
  51. public float affected_population;
  52. public string affected_population_unit;
  53. public float submerged_area_gdp;
  54. public string submerged_area_gdp_unit;
  55. public float flood_loss;
  56. public string flood_loss_unit;
  57. }
  58. [Serializable]
  59. public class PersonnelSupport
  60. {
  61. public int id;
  62. public string person;
  63. public string unit;
  64. public string position;
  65. public string phone;
  66. }
  67. [Serializable]
  68. public class MaterialSupport
  69. {
  70. public int id;
  71. public string type;
  72. public int quantity;
  73. public string unit;
  74. public string person_in_charge;
  75. public string region;
  76. }
  77. [Serializable]
  78. public class Data
  79. {
  80. public SchedulingPlan scheduling_plan;
  81. public SchedulingResults scheduling_results;
  82. public RiskInformation risk_information;
  83. public List<PersonnelSupport> personnel_support;
  84. public List<MaterialSupport> material_support;
  85. }
  86. [Serializable]
  87. public class SchedulingData
  88. {
  89. public int id;
  90. public string scheduling_name;
  91. public Data data;
  92. }
  93. public class XHDDLayer : YZTRootLayer
  94. {
  95. public RectTransform qxhddContent;
  96. public RectTransform xhddContent;
  97. public Button enterBtn;
  98. public Button exitBtn;
  99. public Button playBtn;
  100. public List<Text> threeStepBtns = new List<Text>();
  101. public Dropdown yjDropdown;
  102. public Button[] yjButtons;
  103. public YJType yJType;
  104. public string[,] allYAContent = new string[3, 3];
  105. bool playing = false;
  106. float currentTime = 0;
  107. [Header("UpLeft")]
  108. public Text ddNameText;
  109. public Text zuigaoshuiweiText;
  110. public Text zuigaoshuiweishijianText;
  111. public Text hongfengliusuText;
  112. public Text lanxuhongliangText;
  113. public Text xuefenglvText;
  114. public Text moqishuiweiText;
  115. [Header("MiddleLeft")]
  116. public Text rukuhongfengText;
  117. public Text qitiaoshuiweiText;
  118. public Text chukuzongliuliangText;
  119. public Text mubiaoshuiweiText;
  120. [Header("DownLeft")]
  121. public RectTransform rkzyContent;
  122. public GameObject rkzyPrefab;
  123. [Header("UpRight")]
  124. public Text fengxiandengjiText;
  125. public Text yanmomianjiText;
  126. public Text yanmogengdiText;
  127. public Text yingxiangrenkouText;
  128. public Text gDPText;
  129. public Text hongshuisunshiText;
  130. [Header("MiddleRight")]
  131. public RectTransform rybzContent;
  132. public GameObject rybzPrefab;
  133. [Header("DownRight")]
  134. public RectTransform wzbzContent;
  135. public GameObject wzbzPrefab;
  136. // Start is called before the first frame update
  137. void Start()
  138. {
  139. InitYAContent();
  140. InitButton();
  141. InitUpLeft();
  142. InitMiddleLeft();
  143. InitDownLeft();
  144. InitUpRight();
  145. InitMiddleRight();
  146. InitDownRight();
  147. }
  148. private void OnEnable()
  149. {
  150. CameraManager.SwitchCamera(0);
  151. StaticLod.instance.OnFoucusStatic(1);
  152. }
  153. private void InitUpLeft()
  154. {
  155. ddNameText.text = GlobalData.schedulingData.scheduling_name;
  156. zuigaoshuiweiText.text = $"{GlobalData.schedulingData.data.scheduling_plan.max_water_level} <size=12><color=#A5BBE2>m</color></size>";
  157. zuigaoshuiweishijianText.text = $"{GlobalData.schedulingData.data.scheduling_plan.max_water_level_time}";
  158. hongfengliusuText.text = $"{GlobalData.schedulingData.data.scheduling_plan.flood_peak_flow_rate} <size=12><color=#A5BBE2>m³/s</color></size>";
  159. lanxuhongliangText.text = $"{GlobalData.schedulingData.data.scheduling_plan.intercepted_flood_volume} <size=12><color=#A5BBE2>m³/s</color></size>";
  160. xuefenglvText.text = $"{GlobalData.schedulingData.data.scheduling_plan.peak_reduction_rate} <size=12><color=#A5BBE2>%</color></size>";
  161. moqishuiweiText.text = $"{GlobalData.schedulingData.data.scheduling_plan.final_water_level} <size=12><color=#A5BBE2>m</color></size>";
  162. }
  163. private void InitMiddleLeft()
  164. {
  165. rukuhongfengText.text = $"{GlobalData.schedulingData.data.scheduling_results.inflow_peak} <size=14><color=#A5BBE2>m³/s</color></size>";
  166. qitiaoshuiweiText.text = $"{GlobalData.schedulingData.data.scheduling_results.outflow_total} <size=14><color=#A5BBE2>m</color></size>";
  167. chukuzongliuliangText.text = $"{GlobalData.schedulingData.data.scheduling_results.initial_water_level} <size=14><color=#A5BBE2>m³/s</color></size>";
  168. mubiaoshuiweiText.text = $"{GlobalData.schedulingData.data.scheduling_results.target_water_level} <size=14><color=#A5BBE2>m</color></size>";
  169. }
  170. private async Task InitDownLeft()
  171. {
  172. await new WaitUntil(() =>
  173. {
  174. return GlobalData.allServerMovePlans.Count > 0;
  175. });
  176. for (int i = 0; i < GlobalData.allServerMovePlans.Count; i++)
  177. {
  178. GameObject obj = Instantiate(rkzyPrefab);
  179. obj.transform.SetParent(rkzyContent);
  180. obj.transform.localScale = Vector3.one;
  181. obj.transform.GetChild(0).GetComponent<Text>().text = i.ToString();
  182. obj.transform.GetChild(1).GetComponent<Text>().text = GlobalData.allServerMovePlans[i].from;
  183. obj.transform.GetChild(2).GetComponent<Text>().text = GlobalData.allServerMovePlans[i].to;
  184. obj.transform.GetChild(3).GetComponent<Text>().text = CoordinateConverter.Haversine(GlobalData.allServerMovePlans[i].fromLttd, GlobalData.allServerMovePlans[i].fromLong, GlobalData.allServerMovePlans[i].toLttd, GlobalData.allServerMovePlans[i].toLong).ToString("0.00") + "km";
  185. obj.transform.GetChild(4).GetComponent<Text>().text = GlobalData.allServerMovePlans[i].manNum.ToString();
  186. }
  187. }
  188. private void InitUpRight()
  189. {
  190. fengxiandengjiText.text = $"{GlobalData.schedulingData.data.risk_information.warning_level} <size=14><color=#A5BFE2>级</color></size>";
  191. yanmomianjiText.text = $"{GlobalData.schedulingData.data.risk_information.submerged_area} <size=14><color=#A5BFE2>k㎡</color></size>";
  192. yanmogengdiText.text = $"{GlobalData.schedulingData.data.risk_information.submerged_farmland_area} <size=14><color=#A5BFE2>h㎡</color></size>";
  193. yingxiangrenkouText.text = $"{GlobalData.schedulingData.data.risk_information.affected_population} <size=14><color=#A5BFE2>万人</color></size>";
  194. gDPText.text = $"{GlobalData.schedulingData.data.risk_information.submerged_area_gdp} <size=14><color=#A5BFE2>亿元</color></size>";
  195. hongshuisunshiText.text = $"{GlobalData.schedulingData.data.risk_information.flood_loss} <size=14><color=#A5BFE2>亿元</color></size>";
  196. }
  197. private void InitMiddleRight()
  198. {
  199. for (int i = 0; i < GlobalData.schedulingData.data.personnel_support.Count; i++)
  200. {
  201. GameObject obj = Instantiate(rybzPrefab);
  202. obj.transform.SetParent(rybzContent);
  203. obj.transform.localScale = Vector3.one;
  204. obj.transform.GetChild(0).GetComponent<Text>().text = GlobalData.schedulingData.data.personnel_support[i].id.ToString();
  205. obj.transform.GetChild(1).GetComponent<Text>().text = GlobalData.schedulingData.data.personnel_support[i].person;
  206. obj.transform.GetChild(2).GetComponent<Text>().text = GlobalData.schedulingData.data.personnel_support[i].unit;
  207. obj.transform.GetChild(3).GetComponent<Text>().text = GlobalData.schedulingData.data.personnel_support[i].position.ToString();
  208. obj.transform.GetChild(4).GetComponent<Text>().text = GlobalData.schedulingData.data.personnel_support[i].phone.ToString();
  209. }
  210. }
  211. private void InitDownRight()
  212. {
  213. for (int i = 0; i < GlobalData.schedulingData.data.material_support.Count; i++)
  214. {
  215. GameObject obj = Instantiate(wzbzPrefab);
  216. obj.transform.SetParent(wzbzContent);
  217. obj.transform.localScale = Vector3.one;
  218. obj.transform.GetChild(0).GetComponent<Text>().text = GlobalData.schedulingData.data.material_support[i].id.ToString();
  219. obj.transform.GetChild(1).GetComponent<Text>().text = GlobalData.schedulingData.data.material_support[i].type;
  220. obj.transform.GetChild(2).GetComponent<Text>().text = GlobalData.schedulingData.data.material_support[i].quantity.ToString() + GlobalData.schedulingData.data.material_support[i].unit.ToString();
  221. obj.transform.GetChild(3).GetComponent<Text>().text = GlobalData.schedulingData.data.material_support[i].unit.ToString();
  222. obj.transform.GetChild(4).GetComponent<Text>().text = GlobalData.schedulingData.data.material_support[i].person_in_charge.ToString();
  223. obj.transform.GetChild(5).GetComponent<Text>().text = GlobalData.schedulingData.data.material_support[i].region.ToString();
  224. }
  225. }
  226. public override void OnUILeave()
  227. {
  228. base.OnUILeave();
  229. AllRestore();
  230. }
  231. void InitYAContent()
  232. {
  233. allYAContent[0, 0] = "当预报洪水将达到或超过蓄滞洪区启用标准时(套口进洪闸的设防水位为32m),发布黄色预警,做好运用准备。";
  234. allYAContent[0, 1] = "分洪前线指挥部及其下设七个责任组责任人和成员迅速进入运用准备状态,服从前指的统一调度。";
  235. allYAContent[0, 2] = "分蓄洪区内各个乡镇、村组确定1名领导专门负责承担警报发布和传递任务。警报一经发布,各项避洪工作必须迅速及时,不得有误。";
  236. allYAContent[1, 0] = "当需要区内人员转移时,发布橙色预警,开始实施分蓄洪区内居民转移、清场等工作。";
  237. allYAContent[1, 1] = "人员转移时机根据荆江河段及城陵矶附近地区实时水情、防洪工程情况和区内人员转移所需时间等确定。";
  238. allYAContent[1, 2] = "采取电视、广播、电话、传真、汽笛、敲锣、挂旗、报警器、鸣枪或挨户通知等一切可能的形式迅速向分洪区传播分洪转移命令。";
  239. allYAContent[2, 0] = "当决定启用蓄滞洪区时,发布红色警报。";
  240. allYAContent[2, 1] = "开启套口进洪闸或实施上车湾口门爆破,开始分蓄洪。";
  241. allYAContent[2, 2] = "红色警报期持续至具备返迁条件时为止。";
  242. }
  243. void InitButton()
  244. {
  245. enterBtn.onClick.AddListener(() =>
  246. {
  247. qxhddContent.gameObject.SetActive(false);
  248. xhddContent.gameObject.SetActive(true);
  249. });
  250. exitBtn.onClick.AddListener(() =>
  251. {
  252. qxhddContent.gameObject.SetActive(true);
  253. xhddContent.gameObject.SetActive(false);
  254. playBtn.interactable = true;
  255. playing = false;
  256. AllRestore();
  257. });
  258. for (int i = 0; i < yjButtons.Length; i++)
  259. {
  260. int temp = i;
  261. yjButtons[i].onClick.AddListener(() =>
  262. {
  263. if (!playing)
  264. {
  265. ClearAllText();
  266. }
  267. for (int j = 0; j < yjButtons.Length; j++)
  268. {
  269. yjButtons[j].GetComponent<CanvasGroup>().alpha = 0.2f;
  270. }
  271. yjButtons[temp].GetComponent<CanvasGroup>().alpha = 1f;
  272. yJType = (YJType)temp;
  273. yjDropdown.value = temp;
  274. });
  275. }
  276. playBtn.onClick.AddListener(() =>
  277. {
  278. ClearAllText();
  279. playing = true;
  280. playBtn.interactable = false;
  281. currentTime = 0;
  282. ControlYJ();
  283. });
  284. }
  285. void AllRestore()
  286. {
  287. TimeLineControl.instance.transform.GetChild(1).GetChild(1).localPosition = Vector3.zero;
  288. TimeLineControl.instance.transform.GetChild(0).gameObject.SetActive(false);
  289. Material material = TimeLineControl.instance.transform.GetChild(1).GetChild(0).GetComponent<MeshRenderer>().material;
  290. material.SetFloat("_ClipLength", 1);
  291. currentTime = 0;
  292. }
  293. void ClearAllText()
  294. {
  295. for (int i = 0; i < threeStepBtns.Count; i++)
  296. {
  297. threeStepBtns[i].text = "";
  298. }
  299. }
  300. async void ControlYJ()
  301. {
  302. switch (yJType)
  303. {
  304. case YJType.YELLOW:
  305. TimeLineControl.instance.transform.GetChild(1).GetChild(1).localPosition = Vector3.zero;
  306. threeStepBtns[0].text = allYAContent[(int)yJType, 0];
  307. await new WaitUntil(() =>
  308. {
  309. return currentTime > 1;
  310. });
  311. if (!playing)
  312. {
  313. playBtn.interactable = true;
  314. return;
  315. }
  316. StaticLod.instance.OnFoucusStatic("Bird1");
  317. await new WaitUntil(() =>
  318. {
  319. return currentTime > 3;
  320. });
  321. if (!playing)
  322. {
  323. playBtn.interactable = true;
  324. return;
  325. }
  326. TimeLineControl.instance.transform.GetChild(1).GetChild(1).DOLocalMove(new Vector3(0, 0, 31.2f), 12.0f);
  327. await new WaitUntil(() =>
  328. {
  329. return currentTime > 14;
  330. });
  331. if (!playing)
  332. {
  333. playBtn.interactable = true;
  334. return;
  335. }
  336. threeStepBtns[1].text = allYAContent[(int)yJType, 1];
  337. StaticLod.instance.OnFoucusStatic("Bird2");
  338. await new WaitUntil(() =>
  339. {
  340. return currentTime > 17;
  341. });
  342. if (!playing)
  343. {
  344. playBtn.interactable = true;
  345. return;
  346. }
  347. threeStepBtns[2].text = allYAContent[(int)yJType, 2];
  348. playBtn.interactable = true;
  349. break;
  350. case YJType.ORANGE:
  351. TimeLineControl.instance.transform.GetChild(1).GetChild(1).localPosition = new Vector3(0, 0, 31.2f);
  352. TimeLineControl.instance.transform.GetChild(0).gameObject.SetActive(false);
  353. threeStepBtns[0].text = allYAContent[(int)yJType, 0];
  354. await new WaitUntil(() =>
  355. {
  356. return currentTime > 1;
  357. });
  358. if (!playing)
  359. {
  360. playBtn.interactable = true;
  361. return;
  362. }
  363. StaticLod.instance.OnFoucusStatic("Bird2");
  364. await new WaitUntil(() =>
  365. {
  366. return currentTime > 3;
  367. });
  368. if (!playing)
  369. {
  370. playBtn.interactable = true;
  371. return;
  372. }
  373. TimeLineControl.instance.transform.GetChild(0).gameObject.SetActive(true);
  374. await new WaitUntil(() =>
  375. {
  376. return currentTime > 11;
  377. });
  378. if (!playing)
  379. {
  380. playBtn.interactable = true;
  381. return;
  382. }
  383. threeStepBtns[1].text = allYAContent[(int)yJType, 1];
  384. StaticLod.instance.OnFoucusStatic("Bird3");
  385. await new WaitUntil(() =>
  386. {
  387. return currentTime > 14;
  388. });
  389. if (!playing)
  390. {
  391. playBtn.interactable = true;
  392. return;
  393. }
  394. threeStepBtns[2].text = allYAContent[(int)yJType, 2];
  395. playBtn.interactable = true;
  396. break;
  397. case YJType.RED:
  398. Material material = TimeLineControl.instance.transform.GetChild(1).GetChild(0).GetComponent<MeshRenderer>().material;
  399. TimeLineControl.instance.transform.GetChild(0).gameObject.SetActive(false);
  400. material.SetFloat("_ClipLength", 1);
  401. TimeLineControl.instance.transform.GetChild(1).GetChild(1).localPosition = new Vector3(0, 0, 31.2f);
  402. TimeLineControl.instance.transform.GetChild(2).GetChild(0).gameObject.SetActive(false);
  403. threeStepBtns[0].text = allYAContent[(int)yJType, 0];
  404. await new WaitUntil(() =>
  405. {
  406. return currentTime > 1;
  407. });
  408. if (!playing)
  409. {
  410. playBtn.interactable = true;
  411. return;
  412. }
  413. StaticLod.instance.OnFoucusStatic("Bird2");
  414. await new WaitUntil(() =>
  415. {
  416. return currentTime > 4;
  417. });
  418. if (!playing)
  419. {
  420. playBtn.interactable = true;
  421. return;
  422. }
  423. StaticLod.instance.OnFoucusStatic("Bird4");
  424. ActionInstance._Instance.ModelAni_On?.Invoke();
  425. await new WaitUntil(() =>
  426. {
  427. return currentTime > 5.2;
  428. });
  429. TimeLineControl.instance.transform.GetChild(2).GetChild(0).gameObject.SetActive(true);
  430. if (!playing)
  431. {
  432. playBtn.interactable = true;
  433. return;
  434. }
  435. await new WaitUntil(() =>
  436. {
  437. return currentTime > 5.7;
  438. });
  439. material.SetFloat("_ClipLength", 0.981f);
  440. if (!playing)
  441. {
  442. playBtn.interactable = true;
  443. return;
  444. }
  445. threeStepBtns[1].text = allYAContent[(int)yJType, 1];
  446. await new WaitUntil(() =>
  447. {
  448. return currentTime > 7.7;
  449. });
  450. if (!playing)
  451. {
  452. playBtn.interactable = true;
  453. return;
  454. }
  455. StaticLod.instance.OnFoucusStatic("Bird5");
  456. DOTween.To(() => material.GetFloat("_ClipLength"), x => material.SetFloat("_ClipLength", x), 0.881f, 4f);
  457. await new WaitUntil(() =>
  458. {
  459. return currentTime > 12.7;
  460. });
  461. if (!playing)
  462. {
  463. playBtn.interactable = true;
  464. return;
  465. }
  466. StaticLod.instance.OnFoucusStatic("Bird3");
  467. DOTween.To(() => material.GetFloat("_ClipLength"), x => material.SetFloat("_ClipLength", x), 0.1f, 6f);
  468. await new WaitUntil(() =>
  469. {
  470. return currentTime > 18.7;
  471. });
  472. if (!playing)
  473. {
  474. playBtn.interactable = true;
  475. return;
  476. }
  477. threeStepBtns[2].text = allYAContent[(int)yJType, 2];
  478. playBtn.interactable = true;
  479. break;
  480. }
  481. }
  482. // Update is called once per frame
  483. void Update()
  484. {
  485. currentTime += Time.deltaTime;
  486. }
  487. }