XHDDLayer.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549
  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. [Header("损失概况")]
  137. public GameObject SunShiGaiKuangPanel;
  138. public Text yanMoMianJiText;
  139. public Text yanMoGengDiText;
  140. public Text yanMoRenKouText;
  141. public Text sunShiCaiChanText;
  142. public GameObject sunShiLieBiaoPrefab;
  143. public Transform sunShiLieBiaoContent;
  144. // Start is called before the first frame update
  145. void Start()
  146. {
  147. InitYAContent();
  148. InitButton();
  149. InitUpLeft();
  150. InitMiddleLeft();
  151. InitDownLeft();
  152. InitUpRight();
  153. InitMiddleRight();
  154. InitDownRight();
  155. }
  156. private void OnEnable()
  157. {
  158. CameraManager.SwitchCamera(0);
  159. StaticLod.instance.OnFoucusStatic(1);
  160. TimeLineControl.instance.transform.GetChild(1).GetChild(0).gameObject.SetActive(true);
  161. TimeLineControl.instance.transform.GetChild(1).GetChild(1).gameObject.SetActive(true);
  162. GameObject.FindGameObjectWithTag("HeMianStatic").transform.GetChild(2).gameObject.SetActive(false);
  163. }
  164. private void InitUpLeft()
  165. {
  166. ddNameText.text = GlobalData.schedulingData.scheduling_name;
  167. zuigaoshuiweiText.text = $"{GlobalData.schedulingData.data.scheduling_plan.max_water_level} <size=12><color=#A5BBE2>m</color></size>";
  168. zuigaoshuiweishijianText.text = $"{GlobalData.schedulingData.data.scheduling_plan.max_water_level_time}";
  169. hongfengliusuText.text = $"{GlobalData.schedulingData.data.scheduling_plan.flood_peak_flow_rate} <size=12><color=#A5BBE2>m³/s</color></size>";
  170. lanxuhongliangText.text = $"{GlobalData.schedulingData.data.scheduling_plan.intercepted_flood_volume} <size=12><color=#A5BBE2>m³/s</color></size>";
  171. xuefenglvText.text = $"{GlobalData.schedulingData.data.scheduling_plan.peak_reduction_rate} <size=12><color=#A5BBE2>%</color></size>";
  172. moqishuiweiText.text = $"{GlobalData.schedulingData.data.scheduling_plan.final_water_level} <size=12><color=#A5BBE2>m</color></size>";
  173. }
  174. private void InitMiddleLeft()
  175. {
  176. rukuhongfengText.text = $"{GlobalData.schedulingData.data.scheduling_results.inflow_peak} <size=14><color=#A5BBE2>m³/s</color></size>";
  177. qitiaoshuiweiText.text = $"{GlobalData.schedulingData.data.scheduling_results.outflow_total} <size=14><color=#A5BBE2>m</color></size>";
  178. chukuzongliuliangText.text = $"{GlobalData.schedulingData.data.scheduling_results.initial_water_level} <size=14><color=#A5BBE2>m³/s</color></size>";
  179. mubiaoshuiweiText.text = $"{GlobalData.schedulingData.data.scheduling_results.target_water_level} <size=14><color=#A5BBE2>m</color></size>";
  180. }
  181. private async Task InitDownLeft()
  182. {
  183. await new WaitUntil(() =>
  184. {
  185. return GlobalData.allServerMovePlans.Count > 0;
  186. });
  187. for (int i = 0; i < GlobalData.allServerMovePlans.Count; i++)
  188. {
  189. GameObject obj = Instantiate(rkzyPrefab);
  190. obj.transform.SetParent(rkzyContent);
  191. obj.transform.localScale = Vector3.one;
  192. obj.transform.GetChild(0).GetComponent<Text>().text = i.ToString();
  193. obj.transform.GetChild(1).GetComponent<Text>().text = GlobalData.allServerMovePlans[i].from;
  194. obj.transform.GetChild(2).GetComponent<Text>().text = GlobalData.allServerMovePlans[i].to;
  195. 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";
  196. obj.transform.GetChild(4).GetComponent<Text>().text = GlobalData.allServerMovePlans[i].manNum.ToString();
  197. }
  198. }
  199. private void InitUpRight()
  200. {
  201. fengxiandengjiText.text = $"{GlobalData.schedulingData.data.risk_information.warning_level} <size=14><color=#A5BFE2>级</color></size>";
  202. yanmomianjiText.text = $"{GlobalData.schedulingData.data.risk_information.submerged_area} <size=14><color=#A5BFE2>k㎡</color></size>";
  203. yanmogengdiText.text = $"{GlobalData.schedulingData.data.risk_information.submerged_farmland_area} <size=14><color=#A5BFE2>h㎡</color></size>";
  204. yingxiangrenkouText.text = $"{GlobalData.schedulingData.data.risk_information.affected_population} <size=14><color=#A5BFE2>万人</color></size>";
  205. gDPText.text = $"{GlobalData.schedulingData.data.risk_information.submerged_area_gdp} <size=14><color=#A5BFE2>亿元</color></size>";
  206. hongshuisunshiText.text = $"{GlobalData.schedulingData.data.risk_information.flood_loss} <size=14><color=#A5BFE2>亿元</color></size>";
  207. }
  208. private void InitMiddleRight()
  209. {
  210. for (int i = 0; i < GlobalData.schedulingData.data.personnel_support.Count; i++)
  211. {
  212. GameObject obj = Instantiate(rybzPrefab);
  213. obj.transform.SetParent(rybzContent);
  214. obj.transform.localScale = Vector3.one;
  215. obj.transform.GetChild(0).GetComponent<Text>().text = GlobalData.schedulingData.data.personnel_support[i].id.ToString();
  216. obj.transform.GetChild(1).GetComponent<Text>().text = GlobalData.schedulingData.data.personnel_support[i].person;
  217. obj.transform.GetChild(2).GetComponent<Text>().text = GlobalData.schedulingData.data.personnel_support[i].unit;
  218. obj.transform.GetChild(3).GetComponent<Text>().text = GlobalData.schedulingData.data.personnel_support[i].position.ToString();
  219. obj.transform.GetChild(4).GetComponent<Text>().text = GlobalData.schedulingData.data.personnel_support[i].phone.ToString();
  220. }
  221. }
  222. private void InitDownRight()
  223. {
  224. for (int i = 0; i < GlobalData.schedulingData.data.material_support.Count; i++)
  225. {
  226. GameObject obj = Instantiate(wzbzPrefab);
  227. obj.transform.SetParent(wzbzContent);
  228. obj.transform.localScale = Vector3.one;
  229. obj.transform.GetChild(0).GetComponent<Text>().text = GlobalData.schedulingData.data.material_support[i].id.ToString();
  230. obj.transform.GetChild(1).GetComponent<Text>().text = GlobalData.schedulingData.data.material_support[i].type;
  231. obj.transform.GetChild(2).GetComponent<Text>().text = GlobalData.schedulingData.data.material_support[i].quantity.ToString() + GlobalData.schedulingData.data.material_support[i].unit.ToString();
  232. obj.transform.GetChild(3).GetComponent<Text>().text = GlobalData.schedulingData.data.material_support[i].unit.ToString();
  233. obj.transform.GetChild(4).GetComponent<Text>().text = GlobalData.schedulingData.data.material_support[i].person_in_charge.ToString();
  234. obj.transform.GetChild(5).GetComponent<Text>().text = GlobalData.schedulingData.data.material_support[i].region.ToString();
  235. }
  236. }
  237. public override void OnUILeave()
  238. {
  239. base.OnUILeave();
  240. AllRestore();
  241. }
  242. void InitYAContent()
  243. {
  244. allYAContent[0, 0] = "当预报洪水将达到或超过蓄滞洪区启用标准时(套口进洪闸的设防水位为32m),发布黄色预警,做好运用准备。";
  245. allYAContent[0, 1] = "分洪前线指挥部及其下设七个责任组责任人和成员迅速进入运用准备状态,服从前指的统一调度。";
  246. allYAContent[0, 2] = "分蓄洪区内各个乡镇、村组确定1名领导专门负责承担警报发布和传递任务。警报一经发布,各项避洪工作必须迅速及时,不得有误。";
  247. allYAContent[1, 0] = "当需要区内人员转移时,发布橙色预警,开始实施分蓄洪区内居民转移、清场等工作。";
  248. allYAContent[1, 1] = "人员转移时机根据荆江河段及城陵矶附近地区实时水情、防洪工程情况和区内人员转移所需时间等确定。";
  249. allYAContent[1, 2] = "采取电视、广播、电话、传真、汽笛、敲锣、挂旗、报警器、鸣枪或挨户通知等一切可能的形式迅速向分洪区传播分洪转移命令。";
  250. allYAContent[2, 0] = "当决定启用蓄滞洪区时,发布红色警报。";
  251. allYAContent[2, 1] = "开启套口进洪闸或实施上车湾口门爆破,开始分蓄洪。";
  252. allYAContent[2, 2] = "红色警报期持续至具备返迁条件时为止。";
  253. }
  254. void InitButton()
  255. {
  256. enterBtn.onClick.AddListener(() =>
  257. {
  258. qxhddContent.gameObject.SetActive(false);
  259. xhddContent.gameObject.SetActive(true);
  260. });
  261. exitBtn.onClick.AddListener(() =>
  262. {
  263. qxhddContent.gameObject.SetActive(true);
  264. xhddContent.gameObject.SetActive(false);
  265. playBtn.interactable = true;
  266. playing = false;
  267. AllRestore();
  268. });
  269. for (int i = 0; i < yjButtons.Length; i++)
  270. {
  271. int temp = i;
  272. yjButtons[i].onClick.AddListener(() =>
  273. {
  274. if (!playing)
  275. {
  276. ClearAllText();
  277. }
  278. for (int j = 0; j < yjButtons.Length; j++)
  279. {
  280. yjButtons[j].GetComponent<CanvasGroup>().alpha = 0.2f;
  281. }
  282. yjButtons[temp].GetComponent<CanvasGroup>().alpha = 1f;
  283. yJType = (YJType)temp;
  284. yjDropdown.value = temp;
  285. });
  286. }
  287. playBtn.onClick.AddListener(() =>
  288. {
  289. ClearAllText();
  290. playing = true;
  291. playBtn.interactable = false;
  292. currentTime = 0;
  293. ControlYJ();
  294. });
  295. }
  296. void AllRestore()
  297. {
  298. TimeLineControl.instance.transform.GetChild(1).GetChild(1).localPosition = Vector3.zero;
  299. TimeLineControl.instance.transform.GetChild(0).gameObject.SetActive(false);
  300. TimeLineControl.instance.transform.GetChild(1).GetChild(0).gameObject.SetActive(false);
  301. TimeLineControl.instance.transform.GetChild(1).GetChild(1).gameObject.SetActive(false);
  302. GameObject.FindGameObjectWithTag("HeMianStatic").transform.GetChild(2).gameObject.SetActive(true);
  303. Material material = TimeLineControl.instance.transform.GetChild(1).GetChild(0).GetComponent<MeshRenderer>().material;
  304. material.SetFloat("_ClipLength", 1);
  305. currentTime = 0;
  306. }
  307. void ClearAllText()
  308. {
  309. for (int i = 0; i < threeStepBtns.Count; i++)
  310. {
  311. threeStepBtns[i].text = "";
  312. }
  313. }
  314. async void ControlYJ()
  315. {
  316. switch (yJType)
  317. {
  318. case YJType.YELLOW:
  319. TimeLineControl.instance.transform.GetChild(1).GetChild(1).localPosition = Vector3.zero;
  320. threeStepBtns[0].text = allYAContent[(int)yJType, 0];
  321. await new WaitUntil(() =>
  322. {
  323. return currentTime > 1;
  324. });
  325. if (!playing)
  326. {
  327. playBtn.interactable = true;
  328. return;
  329. }
  330. StaticLod.instance.OnFoucusStatic("Bird1");
  331. await new WaitUntil(() =>
  332. {
  333. return currentTime > 3;
  334. });
  335. if (!playing)
  336. {
  337. playBtn.interactable = true;
  338. return;
  339. }
  340. TimeLineControl.instance.transform.GetChild(1).GetChild(1).DOLocalMove(new Vector3(0, 0, 31.2f), 12.0f);
  341. await new WaitUntil(() =>
  342. {
  343. return currentTime > 14;
  344. });
  345. if (!playing)
  346. {
  347. playBtn.interactable = true;
  348. return;
  349. }
  350. threeStepBtns[1].text = allYAContent[(int)yJType, 1];
  351. StaticLod.instance.OnFoucusStatic("Bird2");
  352. await new WaitUntil(() =>
  353. {
  354. return currentTime > 17;
  355. });
  356. if (!playing)
  357. {
  358. playBtn.interactable = true;
  359. return;
  360. }
  361. threeStepBtns[2].text = allYAContent[(int)yJType, 2];
  362. playBtn.interactable = true;
  363. break;
  364. case YJType.ORANGE:
  365. TimeLineControl.instance.transform.GetChild(1).GetChild(1).localPosition = new Vector3(0, 0, 31.2f);
  366. TimeLineControl.instance.transform.GetChild(0).gameObject.SetActive(false);
  367. threeStepBtns[0].text = allYAContent[(int)yJType, 0];
  368. await new WaitUntil(() =>
  369. {
  370. return currentTime > 1;
  371. });
  372. if (!playing)
  373. {
  374. playBtn.interactable = true;
  375. return;
  376. }
  377. StaticLod.instance.OnFoucusStatic("Bird2");
  378. await new WaitUntil(() =>
  379. {
  380. return currentTime > 3;
  381. });
  382. if (!playing)
  383. {
  384. playBtn.interactable = true;
  385. return;
  386. }
  387. TimeLineControl.instance.transform.GetChild(0).gameObject.SetActive(true);
  388. await new WaitUntil(() =>
  389. {
  390. return currentTime > 11;
  391. });
  392. if (!playing)
  393. {
  394. playBtn.interactable = true;
  395. return;
  396. }
  397. threeStepBtns[1].text = allYAContent[(int)yJType, 1];
  398. StaticLod.instance.OnFoucusStatic("Bird3");
  399. await new WaitUntil(() =>
  400. {
  401. return currentTime > 14;
  402. });
  403. if (!playing)
  404. {
  405. playBtn.interactable = true;
  406. return;
  407. }
  408. threeStepBtns[2].text = allYAContent[(int)yJType, 2];
  409. playBtn.interactable = true;
  410. break;
  411. case YJType.RED:
  412. Material material = TimeLineControl.instance.transform.GetChild(1).GetChild(0).GetComponent<MeshRenderer>().material;
  413. TimeLineControl.instance.transform.GetChild(0).gameObject.SetActive(false);
  414. material.SetFloat("_ClipLength", 1);
  415. TimeLineControl.instance.transform.GetChild(1).GetChild(1).localPosition = new Vector3(0, 0, 31.2f);
  416. TimeLineControl.instance.transform.GetChild(2).GetChild(0).gameObject.SetActive(false);
  417. threeStepBtns[0].text = allYAContent[(int)yJType, 0];
  418. await new WaitUntil(() =>
  419. {
  420. return currentTime > 1;
  421. });
  422. if (!playing)
  423. {
  424. playBtn.interactable = true;
  425. return;
  426. }
  427. StaticLod.instance.OnFoucusStatic("Bird2");
  428. await new WaitUntil(() =>
  429. {
  430. return currentTime > 4;
  431. });
  432. if (!playing)
  433. {
  434. playBtn.interactable = true;
  435. return;
  436. }
  437. StaticLod.instance.OnFoucusStatic("Bird4");
  438. //ActionInstance._Instance.ModelAni_On?.Invoke(null);
  439. await new WaitUntil(() =>
  440. {
  441. return currentTime > 5.2;
  442. });
  443. TimeLineControl.instance.transform.GetChild(2).GetChild(0).gameObject.SetActive(true);
  444. if (!playing)
  445. {
  446. playBtn.interactable = true;
  447. return;
  448. }
  449. await new WaitUntil(() =>
  450. {
  451. return currentTime > 5.7;
  452. });
  453. material.SetFloat("_ClipLength", 0.981f);
  454. if (!playing)
  455. {
  456. playBtn.interactable = true;
  457. return;
  458. }
  459. threeStepBtns[1].text = allYAContent[(int)yJType, 1];
  460. await new WaitUntil(() =>
  461. {
  462. return currentTime > 7.7;
  463. });
  464. if (!playing)
  465. {
  466. playBtn.interactable = true;
  467. return;
  468. }
  469. StaticLod.instance.OnFoucusStatic("Bird5");
  470. DOTween.To(() => material.GetFloat("_ClipLength"), x => material.SetFloat("_ClipLength", x), 0.881f, 4f);
  471. await new WaitUntil(() =>
  472. {
  473. return currentTime > 12.7;
  474. });
  475. if (!playing)
  476. {
  477. playBtn.interactable = true;
  478. return;
  479. }
  480. StaticLod.instance.OnFoucusStatic("Bird3");
  481. DOTween.To(() => material.GetFloat("_ClipLength"), x => material.SetFloat("_ClipLength", x), 0.1f, 6f);
  482. await new WaitUntil(() =>
  483. {
  484. return currentTime > 18.7;
  485. });
  486. if (!playing)
  487. {
  488. playBtn.interactable = true;
  489. return;
  490. }
  491. threeStepBtns[2].text = allYAContent[(int)yJType, 2];
  492. playBtn.interactable = true;
  493. break;
  494. }
  495. }
  496. // Update is called once per frame
  497. void Update()
  498. {
  499. currentTime += Time.deltaTime;
  500. }
  501. }