XHDDLayer.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532
  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].person_in_charge.ToString();
  222. obj.transform.GetChild(4).GetComponent<Text>().text = GlobalData.schedulingData.data.material_support[i].region.ToString();
  223. }
  224. }
  225. public override void OnUILeave()
  226. {
  227. base.OnUILeave();
  228. AllRestore();
  229. }
  230. void InitYAContent()
  231. {
  232. allYAContent[0, 0] = "当预报洪水将达到或超过蓄滞洪区启用标准时(套口进洪闸的设防水位为32m),发布黄色预警,做好运用准备。";
  233. allYAContent[0, 1] = "分洪前线指挥部及其下设七个责任组责任人和成员迅速进入运用准备状态,服从前指的统一调度。";
  234. allYAContent[0, 2] = "分蓄洪区内各个乡镇、村组确定1名领导专门负责承担警报发布和传递任务。警报一经发布,各项避洪工作必须迅速及时,不得有误。";
  235. allYAContent[1, 0] = "当需要区内人员转移时,发布橙色预警,开始实施分蓄洪区内居民转移、清场等工作。";
  236. allYAContent[1, 1] = "人员转移时机根据荆江河段及城陵矶附近地区实时水情、防洪工程情况和区内人员转移所需时间等确定。";
  237. allYAContent[1, 2] = "采取电视、广播、电话、传真、汽笛、敲锣、挂旗、报警器、鸣枪或挨户通知等一切可能的形式迅速向分洪区传播分洪转移命令。";
  238. allYAContent[2, 0] = "当决定启用蓄滞洪区时,发布红色警报。";
  239. allYAContent[2, 1] = "开启套口进洪闸或实施上车湾口门爆破,开始分蓄洪。";
  240. allYAContent[2, 2] = "红色警报期持续至具备返迁条件时为止。";
  241. }
  242. void InitButton()
  243. {
  244. enterBtn.onClick.AddListener(() =>
  245. {
  246. qxhddContent.gameObject.SetActive(false);
  247. xhddContent.gameObject.SetActive(true);
  248. });
  249. exitBtn.onClick.AddListener(() =>
  250. {
  251. qxhddContent.gameObject.SetActive(true);
  252. xhddContent.gameObject.SetActive(false);
  253. playBtn.interactable = true;
  254. playing = false;
  255. AllRestore();
  256. });
  257. for (int i = 0; i < yjButtons.Length; i++)
  258. {
  259. int temp = i;
  260. yjButtons[i].onClick.AddListener(() =>
  261. {
  262. if (!playing)
  263. {
  264. ClearAllText();
  265. }
  266. for (int j = 0; j < yjButtons.Length; j++)
  267. {
  268. yjButtons[j].GetComponent<CanvasGroup>().alpha = 0.2f;
  269. }
  270. yjButtons[temp].GetComponent<CanvasGroup>().alpha = 1f;
  271. yJType = (YJType)temp;
  272. yjDropdown.value = temp;
  273. });
  274. }
  275. playBtn.onClick.AddListener(() =>
  276. {
  277. ClearAllText();
  278. playing = true;
  279. playBtn.interactable = false;
  280. currentTime = 0;
  281. ControlYJ();
  282. });
  283. }
  284. void AllRestore()
  285. {
  286. TimeLineControl.instance.transform.GetChild(1).GetChild(1).localPosition = Vector3.zero;
  287. TimeLineControl.instance.transform.GetChild(0).gameObject.SetActive(false);
  288. Material material = TimeLineControl.instance.transform.GetChild(1).GetChild(0).GetComponent<MeshRenderer>().material;
  289. material.SetFloat("_ClipLength", 1);
  290. currentTime = 0;
  291. }
  292. void ClearAllText()
  293. {
  294. for (int i = 0; i < threeStepBtns.Count; i++)
  295. {
  296. threeStepBtns[i].text = "";
  297. }
  298. }
  299. async void ControlYJ()
  300. {
  301. switch (yJType)
  302. {
  303. case YJType.YELLOW:
  304. TimeLineControl.instance.transform.GetChild(1).GetChild(1).localPosition = Vector3.zero;
  305. threeStepBtns[0].text = allYAContent[(int)yJType, 0];
  306. await new WaitUntil(() =>
  307. {
  308. return currentTime > 1;
  309. });
  310. if (!playing)
  311. {
  312. playBtn.interactable = true;
  313. return;
  314. }
  315. StaticLod.instance.OnFoucusStatic("Bird1");
  316. await new WaitUntil(() =>
  317. {
  318. return currentTime > 3;
  319. });
  320. if (!playing)
  321. {
  322. playBtn.interactable = true;
  323. return;
  324. }
  325. TimeLineControl.instance.transform.GetChild(1).GetChild(1).DOLocalMove(new Vector3(0, 0, 31.2f), 12.0f);
  326. await new WaitUntil(() =>
  327. {
  328. return currentTime > 14;
  329. });
  330. if (!playing)
  331. {
  332. playBtn.interactable = true;
  333. return;
  334. }
  335. threeStepBtns[1].text = allYAContent[(int)yJType, 1];
  336. StaticLod.instance.OnFoucusStatic("Bird2");
  337. await new WaitUntil(() =>
  338. {
  339. return currentTime > 17;
  340. });
  341. if (!playing)
  342. {
  343. playBtn.interactable = true;
  344. return;
  345. }
  346. threeStepBtns[2].text = allYAContent[(int)yJType, 2];
  347. playBtn.interactable = true;
  348. break;
  349. case YJType.ORANGE:
  350. TimeLineControl.instance.transform.GetChild(1).GetChild(1).localPosition = new Vector3(0, 0, 31.2f);
  351. TimeLineControl.instance.transform.GetChild(0).gameObject.SetActive(false);
  352. threeStepBtns[0].text = allYAContent[(int)yJType, 0];
  353. await new WaitUntil(() =>
  354. {
  355. return currentTime > 1;
  356. });
  357. if (!playing)
  358. {
  359. playBtn.interactable = true;
  360. return;
  361. }
  362. StaticLod.instance.OnFoucusStatic("Bird2");
  363. await new WaitUntil(() =>
  364. {
  365. return currentTime > 3;
  366. });
  367. if (!playing)
  368. {
  369. playBtn.interactable = true;
  370. return;
  371. }
  372. TimeLineControl.instance.transform.GetChild(0).gameObject.SetActive(true);
  373. await new WaitUntil(() =>
  374. {
  375. return currentTime > 11;
  376. });
  377. if (!playing)
  378. {
  379. playBtn.interactable = true;
  380. return;
  381. }
  382. threeStepBtns[1].text = allYAContent[(int)yJType, 1];
  383. StaticLod.instance.OnFoucusStatic("Bird3");
  384. await new WaitUntil(() =>
  385. {
  386. return currentTime > 14;
  387. });
  388. if (!playing)
  389. {
  390. playBtn.interactable = true;
  391. return;
  392. }
  393. threeStepBtns[2].text = allYAContent[(int)yJType, 2];
  394. playBtn.interactable = true;
  395. break;
  396. case YJType.RED:
  397. Material material = TimeLineControl.instance.transform.GetChild(1).GetChild(0).GetComponent<MeshRenderer>().material;
  398. TimeLineControl.instance.transform.GetChild(0).gameObject.SetActive(false);
  399. material.SetFloat("_ClipLength", 1);
  400. TimeLineControl.instance.transform.GetChild(1).GetChild(1).localPosition = new Vector3(0, 0, 31.2f);
  401. TimeLineControl.instance.transform.GetChild(2).GetChild(0).gameObject.SetActive(false);
  402. threeStepBtns[0].text = allYAContent[(int)yJType, 0];
  403. await new WaitUntil(() =>
  404. {
  405. return currentTime > 1;
  406. });
  407. if (!playing)
  408. {
  409. playBtn.interactable = true;
  410. return;
  411. }
  412. StaticLod.instance.OnFoucusStatic("Bird2");
  413. await new WaitUntil(() =>
  414. {
  415. return currentTime > 4;
  416. });
  417. if (!playing)
  418. {
  419. playBtn.interactable = true;
  420. return;
  421. }
  422. StaticLod.instance.OnFoucusStatic("Bird4");
  423. ActionInstance._Instance.ModelAni_On?.Invoke();
  424. await new WaitUntil(() =>
  425. {
  426. return currentTime > 5.2;
  427. });
  428. TimeLineControl.instance.transform.GetChild(2).GetChild(0).gameObject.SetActive(true);
  429. if (!playing)
  430. {
  431. playBtn.interactable = true;
  432. return;
  433. }
  434. await new WaitUntil(() =>
  435. {
  436. return currentTime > 5.7;
  437. });
  438. material.SetFloat("_ClipLength", 0.981f);
  439. if (!playing)
  440. {
  441. playBtn.interactable = true;
  442. return;
  443. }
  444. threeStepBtns[1].text = allYAContent[(int)yJType, 1];
  445. await new WaitUntil(() =>
  446. {
  447. return currentTime > 7.7;
  448. });
  449. if (!playing)
  450. {
  451. playBtn.interactable = true;
  452. return;
  453. }
  454. StaticLod.instance.OnFoucusStatic("Bird5");
  455. DOTween.To(() => material.GetFloat("_ClipLength"), x => material.SetFloat("_ClipLength", x), 0.881f, 4f);
  456. await new WaitUntil(() =>
  457. {
  458. return currentTime > 12.7;
  459. });
  460. if (!playing)
  461. {
  462. playBtn.interactable = true;
  463. return;
  464. }
  465. StaticLod.instance.OnFoucusStatic("Bird3");
  466. DOTween.To(() => material.GetFloat("_ClipLength"), x => material.SetFloat("_ClipLength", x), 0.1f, 6f);
  467. await new WaitUntil(() =>
  468. {
  469. return currentTime > 18.7;
  470. });
  471. if (!playing)
  472. {
  473. playBtn.interactable = true;
  474. return;
  475. }
  476. threeStepBtns[2].text = allYAContent[(int)yJType, 2];
  477. playBtn.interactable = true;
  478. break;
  479. }
  480. }
  481. // Update is called once per frame
  482. void Update()
  483. {
  484. currentTime += Time.deltaTime;
  485. }
  486. }