XHDDLayer.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503
  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 UnityEditor.VersionControl;
  8. using UnityEngine;
  9. using UnityEngine.UI;
  10. using WaitUntil = UnityAsync.WaitUntil;
  11. [System.Serializable]
  12. public enum YJType
  13. {
  14. BLUE,
  15. YELLOW,
  16. ORANGE,
  17. RED
  18. }
  19. [Serializable]
  20. public class SchedulingPlan
  21. {
  22. public float max_water_level;
  23. public string max_water_level_unit;
  24. public string max_water_level_time;
  25. public float flood_peak_flow_rate;
  26. public string flood_peak_flow_rate_unit;
  27. public float intercepted_flood_volume;
  28. public string intercepted_flood_volume_unit;
  29. public int peak_reduction_rate;
  30. public float final_water_level;
  31. public string final_water_level_unit;
  32. }
  33. [Serializable]
  34. public class SchedulingResults
  35. {
  36. public float inflow_peak;
  37. public string inflow_peak_unit;
  38. public float outflow_total;
  39. public string outflow_total_unit;
  40. public float initial_water_level;
  41. public string initial_water_level_unit;
  42. public float target_water_level;
  43. public string target_water_level_unit;
  44. }
  45. [Serializable]
  46. public class RiskInformation
  47. {
  48. public string warning_level;
  49. public float submerged_area;
  50. public string submerged_area_unit;
  51. public float submerged_farmland_area;
  52. public string submerged_farmland_area_unit;
  53. public float affected_population;
  54. public string affected_population_unit;
  55. public float submerged_area_gdp;
  56. public string submerged_area_gdp_unit;
  57. public float flood_loss;
  58. public string flood_loss_unit;
  59. }
  60. [Serializable]
  61. public class PersonnelSupport
  62. {
  63. public int id;
  64. public string person;
  65. public string unit;
  66. public string position;
  67. public string phone;
  68. }
  69. [Serializable]
  70. public class MaterialSupport
  71. {
  72. public int id;
  73. public string type;
  74. public int quantity;
  75. public string unit;
  76. public string person_in_charge;
  77. public string region;
  78. }
  79. [Serializable]
  80. public class Data
  81. {
  82. public SchedulingPlan scheduling_plan;
  83. public SchedulingResults scheduling_results;
  84. public RiskInformation risk_information;
  85. public List<PersonnelSupport> personnel_support;
  86. public List<MaterialSupport> material_support;
  87. }
  88. [Serializable]
  89. public class SchedulingData
  90. {
  91. public int id;
  92. public string scheduling_name;
  93. public Data data;
  94. }
  95. public class XHDDLayer : YZTRootLayer
  96. {
  97. public RectTransform qxhddContent;
  98. public RectTransform xhddContent;
  99. private bool inAniamtion = false;
  100. public Button enterBtn;
  101. public Button exitBtn;
  102. public Dropdown yjDropdown;
  103. public Button[] yjButtons;
  104. public YJType yJType = YJType.BLUE;
  105. public bool playing = false;
  106. float currentTime = 0;
  107. [Header("DownLeft")]
  108. public RectTransform rkzyContent;
  109. public GameObject rkzyPrefab;
  110. [Header("UpRight")]
  111. public Text yanmomianjiText;
  112. public Text yanmogengdiText;
  113. public Text yingxiangrenkouText;
  114. public Text gDPText;
  115. public Text hongshuisunshiText;
  116. [Header("MiddleRight")]
  117. public RectTransform rybzContent;
  118. public GameObject rybzPrefab;
  119. [Header("DownRight")]
  120. public RectTransform wzbzContent;
  121. public GameObject wzbzPrefab;
  122. [Header("损失概况")]
  123. public GameObject SunShiGaiKuangPanel;
  124. public Text yanMoMianJiText;
  125. public Text yanMoGengDiText;
  126. public Text yanMoRenKouText;
  127. public Text sunShiCaiChanText;
  128. public GameObject sunShiLieBiaoPrefab;
  129. public Transform sunShiLieBiaoContent;
  130. public GameObject mask;
  131. // Start is called before the first frame update
  132. void Start()
  133. {
  134. InitButton();
  135. InitUpLeft();
  136. InitDownLeft();
  137. InitUpRight();
  138. InitDownRight();
  139. }
  140. private void OnEnable()
  141. {
  142. CameraManager.SwitchCamera(0);
  143. StaticLod.instance.OnFoucusStatic(1);
  144. TimeLineControl.instance.transform.GetChild(1).GetChild(0).gameObject.SetActive(true);
  145. TimeLineControl.instance.transform.GetChild(1).GetChild(1).gameObject.SetActive(true);
  146. GameObject.FindGameObjectWithTag("HeMianStatic").transform.GetChild(2).gameObject.SetActive(false);
  147. }
  148. private async Task InitDownLeft()
  149. {
  150. await new WaitUntil(() =>
  151. {
  152. return GlobalData.allServerMovePlans.Count > 0;
  153. });
  154. for (int i = 0; i < GlobalData.allServerMovePlans.Count; i++)
  155. {
  156. GameObject obj = Instantiate(rkzyPrefab);
  157. obj.transform.SetParent(rkzyContent);
  158. obj.transform.localScale = Vector3.one;
  159. obj.transform.GetChild(0).GetComponent<Text>().text = i.ToString();
  160. obj.transform.GetChild(1).GetComponent<Text>().text = GlobalData.allServerMovePlans[i].from;
  161. obj.transform.GetChild(2).GetComponent<Text>().text = GlobalData.allServerMovePlans[i].to;
  162. 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";
  163. obj.transform.GetChild(4).GetComponent<Text>().text = GlobalData.allServerMovePlans[i].manNum.ToString();
  164. }
  165. }
  166. private void InitUpLeft()
  167. {
  168. yanmomianjiText.text = $"{GlobalData.schedulingData.data.risk_information.submerged_area} <size=14><color=#A5BFE2>k㎡</color></size>";
  169. yanmogengdiText.text = $"{GlobalData.schedulingData.data.risk_information.submerged_farmland_area} <size=14><color=#A5BFE2>h㎡</color></size>";
  170. yingxiangrenkouText.text = $"{GlobalData.schedulingData.data.risk_information.affected_population} <size=14><color=#A5BFE2>万人</color></size>";
  171. gDPText.text = $"{GlobalData.schedulingData.data.risk_information.submerged_area_gdp} <size=14><color=#A5BFE2>亿元</color></size>";
  172. hongshuisunshiText.text = $"{GlobalData.schedulingData.data.risk_information.flood_loss} <size=14><color=#A5BFE2>亿元</color></size>";
  173. }
  174. private void InitUpRight()
  175. {
  176. for (int i = 0; i < GlobalData.schedulingData.data.personnel_support.Count; i++)
  177. {
  178. GameObject obj = Instantiate(rybzPrefab);
  179. obj.transform.SetParent(rybzContent);
  180. obj.transform.localScale = Vector3.one;
  181. obj.transform.GetChild(0).GetComponent<Text>().text = GlobalData.schedulingData.data.personnel_support[i].id.ToString();
  182. obj.transform.GetChild(1).GetComponent<Text>().text = GlobalData.schedulingData.data.personnel_support[i].person;
  183. obj.transform.GetChild(2).GetComponent<Text>().text = GlobalData.schedulingData.data.personnel_support[i].unit;
  184. obj.transform.GetChild(3).GetComponent<Text>().text = GlobalData.schedulingData.data.personnel_support[i].position.ToString();
  185. obj.transform.GetChild(4).GetComponent<Text>().text = GlobalData.schedulingData.data.personnel_support[i].phone.ToString();
  186. }
  187. }
  188. private void InitDownRight()
  189. {
  190. for (int i = 0; i < GlobalData.schedulingData.data.material_support.Count; i++)
  191. {
  192. GameObject obj = Instantiate(wzbzPrefab);
  193. obj.transform.SetParent(wzbzContent);
  194. obj.transform.localScale = Vector3.one;
  195. obj.transform.GetChild(0).GetComponent<Text>().text = GlobalData.schedulingData.data.material_support[i].id.ToString();
  196. obj.transform.GetChild(1).GetComponent<Text>().text = GlobalData.schedulingData.data.material_support[i].type;
  197. obj.transform.GetChild(2).GetComponent<Text>().text = GlobalData.schedulingData.data.material_support[i].quantity.ToString() + GlobalData.schedulingData.data.material_support[i].unit.ToString();
  198. obj.transform.GetChild(3).GetComponent<Text>().text = GlobalData.schedulingData.data.material_support[i].unit.ToString();
  199. obj.transform.GetChild(4).GetComponent<Text>().text = GlobalData.schedulingData.data.material_support[i].person_in_charge.ToString();
  200. obj.transform.GetChild(5).GetComponent<Text>().text = GlobalData.schedulingData.data.material_support[i].region.ToString();
  201. }
  202. }
  203. public override void OnUILeave()
  204. {
  205. base.OnUILeave();
  206. OnExitXHDDYS();
  207. }
  208. void OnExitXHDDYS()
  209. {
  210. qxhddContent.gameObject.SetActive(true);
  211. xhddContent.gameObject.SetActive(false);
  212. inAniamtion = false;
  213. GameObject tkobj = StaticLod.instance.staticImportants[1].gameObject;
  214. tkobj.transform.GetChild(1).GetComponent<Animator>().Play("ZhaMenEmpty");
  215. mask.gameObject.SetActive(false);
  216. playing = false;
  217. AllRestore();
  218. }
  219. void InitButton()
  220. {
  221. enterBtn.onClick.AddListener(() =>
  222. {
  223. qxhddContent.gameObject.SetActive(false);
  224. xhddContent.gameObject.SetActive(true);
  225. inAniamtion = true;
  226. });
  227. exitBtn.onClick.AddListener(OnExitXHDDYS);
  228. for (int i = 0; i < yjButtons.Length; i++)
  229. {
  230. int temp = i;
  231. yjButtons[i].onClick.AddListener(() =>
  232. {
  233. if (!playing)
  234. {
  235. }
  236. for (int j = 0; j < yjButtons.Length; j++)
  237. {
  238. yjButtons[j].GetComponent<CanvasGroup>().alpha = 0.2f;
  239. }
  240. yjButtons[temp].GetComponent<CanvasGroup>().alpha = 1f;
  241. yJType = (YJType)(temp);
  242. currentTime = 0;
  243. ControlYJ();
  244. });
  245. }
  246. }
  247. void AllRestore()
  248. {
  249. TimeLineControl.instance.transform.GetChild(1).GetChild(1).localPosition = Vector3.zero;
  250. TimeLineControl.instance.transform.GetChild(0).gameObject.SetActive(false);
  251. GameObject.FindGameObjectWithTag("HeMianStatic").transform.GetChild(2).gameObject.SetActive(true);
  252. Material material = TimeLineControl.instance.transform.GetChild(1).GetChild(0).GetComponent<MeshRenderer>().material;
  253. material.SetFloat("_ClipLength", 1);
  254. currentTime = 0;
  255. }
  256. async void ControlYJ()
  257. {
  258. switch (yJType)
  259. {
  260. case YJType.YELLOW:
  261. TimeLineControl.instance.transform.GetChild(1).GetChild(1).localPosition = Vector3.zero;
  262. await new WaitUntil(() =>
  263. {
  264. return currentTime > 1;
  265. });
  266. if (!playing)
  267. {
  268. mask.gameObject.SetActive(false);
  269. return;
  270. }
  271. StaticLod.instance.OnFoucusStatic("Bird1");
  272. await new WaitUntil(() =>
  273. {
  274. return currentTime > 3;
  275. });
  276. if (!playing)
  277. {
  278. mask.gameObject.SetActive(false);
  279. return;
  280. }
  281. TimeLineControl.instance.transform.GetChild(1).GetChild(1).DOLocalMove(new Vector3(0, 0, 31.2f), 12.0f);
  282. await new WaitUntil(() =>
  283. {
  284. return currentTime > 14;
  285. });
  286. if (!playing)
  287. {
  288. mask.gameObject.SetActive(false);
  289. return;
  290. }
  291. StaticLod.instance.OnFoucusStatic("Bird2");
  292. await new WaitUntil(() =>
  293. {
  294. return currentTime > 17;
  295. });
  296. if (!playing)
  297. {
  298. mask.gameObject.SetActive(false);
  299. return;
  300. }
  301. mask.gameObject.SetActive(false);
  302. break;
  303. case YJType.ORANGE:
  304. TimeLineControl.instance.transform.GetChild(1).GetChild(1).localPosition = new Vector3(0, 0, 31.2f);
  305. TimeLineControl.instance.transform.GetChild(0).gameObject.SetActive(false);
  306. await new WaitUntil(() =>
  307. {
  308. return currentTime > 1;
  309. });
  310. if (!playing)
  311. {
  312. mask.gameObject.SetActive(false);
  313. return;
  314. }
  315. StaticLod.instance.OnFoucusStatic("Bird3");
  316. await new WaitUntil(() =>
  317. {
  318. return currentTime > 3;
  319. });
  320. if (!playing)
  321. {
  322. mask.gameObject.SetActive(false);
  323. return;
  324. }
  325. TimeLineControl.instance.transform.GetChild(0).gameObject.SetActive(true);
  326. await new WaitUntil(() =>
  327. {
  328. return currentTime > 11;
  329. });
  330. if (!playing)
  331. {
  332. mask.gameObject.SetActive(false);
  333. return;
  334. }
  335. //StaticLod.instance.OnFoucusStatic("Bird3");
  336. await new WaitUntil(() =>
  337. {
  338. return currentTime > 14;
  339. });
  340. if (!playing)
  341. {
  342. mask.gameObject.SetActive(false);
  343. return;
  344. }
  345. mask.gameObject.SetActive(false);
  346. break;
  347. case YJType.RED:
  348. Material material = TimeLineControl.instance.transform.GetChild(1).GetChild(0).GetComponent<MeshRenderer>().material;
  349. TimeLineControl.instance.transform.GetChild(0).gameObject.SetActive(false);
  350. material.SetFloat("_ClipLength", 1);
  351. TimeLineControl.instance.transform.GetChild(1).GetChild(1).localPosition = new Vector3(0, 0, 31.2f);
  352. await new WaitUntil(() =>
  353. {
  354. return currentTime > 1;
  355. });
  356. if (!playing)
  357. {
  358. mask.gameObject.SetActive(false);
  359. return;
  360. }
  361. StaticLod.instance.OnFoucusStatic("Bird2");
  362. await new WaitUntil(() =>
  363. {
  364. return currentTime > 4;
  365. });
  366. if (!playing)
  367. {
  368. mask.gameObject.SetActive(false);
  369. return;
  370. }
  371. StaticLod.instance.OnFoucusStatic("Bird4");
  372. GameObject tkobj = StaticLod.instance.staticImportants[1].gameObject;
  373. tkobj.transform.GetChild(1).GetComponent<Animator>().Play("ZhaMen");
  374. await new WaitUntil(() =>
  375. {
  376. return currentTime > 5.2;
  377. });
  378. if (!playing)
  379. {
  380. mask.gameObject.SetActive(false);
  381. return;
  382. }
  383. await new WaitUntil(() =>
  384. {
  385. return currentTime > 6.7;
  386. });
  387. StaticLod.instance.OnFoucusStatic("Bird5");
  388. CameraManager.instance.mainCamera.GetComponent<CameraBird>().target.DOLocalMoveX(2650, 7.0f);
  389. await new WaitUntil(() =>
  390. {
  391. return currentTime > 14.7;
  392. });
  393. material.SetFloat("_ClipLength", 1f);
  394. DOTween.To(() => material.GetFloat("_ClipLength"), x => material.SetFloat("_ClipLength", x), 0.981f, 2f);
  395. if (!playing)
  396. {
  397. mask.gameObject.SetActive(false);
  398. return;
  399. }
  400. await new WaitUntil(() =>
  401. {
  402. return currentTime > 15.7;
  403. });
  404. if (!playing)
  405. {
  406. mask.gameObject.SetActive(false);
  407. return;
  408. }
  409. //StaticLod.instance.OnFoucusStatic("Bird5");
  410. DOTween.To(() => material.GetFloat("_ClipLength"), x => material.SetFloat("_ClipLength", x), 0.881f, 4f);
  411. await new WaitUntil(() =>
  412. {
  413. return currentTime > 20.7;
  414. });
  415. if (!playing)
  416. {
  417. mask.gameObject.SetActive(false);
  418. return;
  419. }
  420. StaticLod.instance.OnFoucusStatic("Bird3");
  421. DOTween.To(() => material.GetFloat("_ClipLength"), x => material.SetFloat("_ClipLength", x), 0.1f, 6f);
  422. await new WaitUntil(() =>
  423. {
  424. return currentTime > 26.7;
  425. });
  426. if (!playing)
  427. {
  428. mask.gameObject.SetActive(false);
  429. return;
  430. }
  431. mask.gameObject.SetActive(false);
  432. break;
  433. }
  434. }
  435. // Update is called once per frame
  436. void Update()
  437. {
  438. currentTime += Time.deltaTime;
  439. GameObject tkobj = StaticLod.instance.staticImportants[1].gameObject;
  440. tkobj.transform.GetChild(1).gameObject.SetActive(inAniamtion);
  441. tkobj.transform.GetChild(tkobj.transform.childCount - 1).gameObject.SetActive(!inAniamtion);
  442. }
  443. }