XHDDLayer.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809
  1. using DG.Tweening;
  2. using System;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using System.Threading;
  6. using System.Threading.Tasks;
  7. using UnityAsync;
  8. //using UnityEditor.VersionControl;
  9. using UnityEngine;
  10. using UnityEngine.UI;
  11. using WaitUntil = UnityAsync.WaitUntil;
  12. [Serializable]
  13. public class AllRegionData
  14. {
  15. public List<RegionData> regions;
  16. }
  17. [Serializable]
  18. public class RegionData
  19. {
  20. public string region;
  21. public string responsibility;
  22. public List<MemberData> members;
  23. }
  24. [Serializable]
  25. public class MemberData
  26. {
  27. public string village;
  28. public string position;
  29. public string name;
  30. public string phone;
  31. }
  32. [Serializable]
  33. public class EmergencyResponseData
  34. {
  35. public List<ResponseMember> LDS;
  36. }
  37. [Serializable]
  38. public class ResponseMember
  39. {
  40. public string unit;
  41. public string position;
  42. public string name;
  43. public string phone;
  44. public string responsibility;
  45. }
  46. [Serializable]
  47. public class XHDDAlertData
  48. {
  49. public string id;
  50. public string title;
  51. public AllAlert allAlert;
  52. public List<RegionData> rkzygb;
  53. public List<ResponseMember> rkzyld;
  54. }
  55. [Serializable]
  56. public class AllAlert
  57. {
  58. public AlertInfo blueAlert;
  59. public AlertInfo yellowAlert;
  60. public AlertInfo orangeAlert;
  61. public AlertInfo redAlert;
  62. }
  63. [Serializable]
  64. public class AlertInfo
  65. {
  66. public string publishCondition;
  67. public string coreGoal;
  68. public List<TaskItem> tasks;
  69. public List<OriginalSection> originalSections;
  70. }
  71. [Serializable]
  72. public class TaskItem
  73. {
  74. public string title;
  75. public string items;
  76. }
  77. [Serializable]
  78. public class OriginalSection
  79. {
  80. public string title;
  81. public string content;
  82. }
  83. [System.Serializable]
  84. public enum YJType
  85. {
  86. BLUE,
  87. YELLOW,
  88. ORANGE,
  89. RED
  90. }
  91. [Serializable]
  92. public class SchedulingPlan
  93. {
  94. public float max_water_level;
  95. public string max_water_level_unit;
  96. public string max_water_level_time;
  97. public float flood_peak_flow_rate;
  98. public string flood_peak_flow_rate_unit;
  99. public float intercepted_flood_volume;
  100. public string intercepted_flood_volume_unit;
  101. public int peak_reduction_rate;
  102. public float final_water_level;
  103. public string final_water_level_unit;
  104. }
  105. [Serializable]
  106. public class SchedulingResults
  107. {
  108. public float inflow_peak;
  109. public string inflow_peak_unit;
  110. public float outflow_total;
  111. public string outflow_total_unit;
  112. public float initial_water_level;
  113. public string initial_water_level_unit;
  114. public float target_water_level;
  115. public string target_water_level_unit;
  116. }
  117. [Serializable]
  118. public class RiskInformation
  119. {
  120. public string warning_level;
  121. public float submerged_area;
  122. public string submerged_area_unit;
  123. public float submerged_farmland_area;
  124. public string submerged_farmland_area_unit;
  125. public float affected_population;
  126. public string affected_population_unit;
  127. public float submerged_area_gdp;
  128. public string submerged_area_gdp_unit;
  129. public float flood_loss;
  130. public string flood_loss_unit;
  131. }
  132. [Serializable]
  133. public class PersonnelSupport
  134. {
  135. public int id;
  136. public string person;
  137. public string unit;
  138. public string position;
  139. public string phone;
  140. }
  141. [Serializable]
  142. public class MaterialSupport
  143. {
  144. public int id;
  145. public string type;
  146. public int quantity;
  147. public string unit;
  148. public string person_in_charge;
  149. public string region;
  150. }
  151. [Serializable]
  152. public class Data
  153. {
  154. public SchedulingPlan scheduling_plan;
  155. public SchedulingResults scheduling_results;
  156. public RiskInformation risk_information;
  157. public List<PersonnelSupport> personnel_support;
  158. public List<MaterialSupport> material_support;
  159. }
  160. [Serializable]
  161. public class SchedulingData
  162. {
  163. public int id;
  164. public string scheduling_name;
  165. public Data data;
  166. }
  167. public class XHDDLayer : YZTRootLayer
  168. {
  169. private CancellationTokenSource yjCTS;
  170. public RectTransform qxhddContent;
  171. public RectTransform xhddContent;
  172. private bool inAniamtion = false;
  173. public Button enterBtn;
  174. public Button exitBtn;
  175. public Dropdown yjDropdown;
  176. public Button[] yjButtons;
  177. public YJType yJType = YJType.BLUE;
  178. public bool playing = false;
  179. float currentTime = 0;
  180. [Header("DownLeft")]
  181. public RectTransform rkzyContent;
  182. public GameObject rkzyPrefab;
  183. [Header("UpRight")]
  184. public Text yanmomianjiText;
  185. public Text yanmogengdiText;
  186. public Text yingxiangrenkouText;
  187. public Text gDPText;
  188. public Text hongshuisunshiText;
  189. [Header("MiddleRight")]
  190. public RectTransform rybzContent;
  191. public GameObject rybzPrefab;
  192. [Header("DownRight")]
  193. public RectTransform wzbzContent;
  194. public GameObject wzbzPrefab;
  195. [Header("损失概况")]
  196. public GameObject SunShiGaiKuangPanel;
  197. public Text yanMoMianJiText;
  198. public Text yanMoGengDiText;
  199. public Text yanMoRenKouText;
  200. public Text sunShiCaiChanText;
  201. public GameObject sunShiLieBiaoPrefab;
  202. public Transform sunShiLieBiaoContent;
  203. public GameObject mask;
  204. public Text yjTitle;
  205. public Text fbsjText;
  206. public VerticalLayoutGroup zyrwContent;
  207. public Text hxmbText;
  208. public VerticalLayoutGroup zxmxContent;
  209. public VerticalLayoutGroup yrzzContent;
  210. public VerticalLayoutGroup xgxzContent;
  211. public Dropdown regionDropdown;
  212. public GameObject titleContentPrefab;
  213. public GameObject g0;
  214. public GameObject g1;
  215. public ParticleSystem particle1;
  216. GameObject moveParentObj;
  217. // Start is called before the first frame update
  218. void Start()
  219. {
  220. InitButton();
  221. InitUpLeft();
  222. InitDownLeft();
  223. InitUpRight();
  224. InitDownRight();
  225. }
  226. private void OnEnable()
  227. {
  228. CameraManager.SwitchCamera(0);
  229. StaticLod.instance.OnFoucusStatic(1);
  230. TimeLineControl.instance.transform.GetChild(1).GetChild(0).gameObject.SetActive(true);
  231. TimeLineControl.instance.transform.GetChild(1).GetChild(1).gameObject.SetActive(true);
  232. GameObject.FindGameObjectWithTag("HeMianStatic").transform.GetChild(2).gameObject.SetActive(false);
  233. }
  234. private async Task InitDownLeft()
  235. {
  236. await new WaitUntil(() =>
  237. {
  238. return GlobalData.allServerMovePlans.Count > 0;
  239. });
  240. moveParentObj = new GameObject($"MovePlan");
  241. for (int i = 0; i < GlobalData.allServerMovePlans.Count; i++)
  242. {
  243. var plan = GlobalData.allServerMovePlans[i];
  244. // UI部分
  245. GameObject obj = Instantiate(rkzyPrefab);
  246. obj.transform.SetParent(rkzyContent);
  247. obj.transform.localScale = Vector3.one;
  248. obj.transform.GetChild(0).GetComponent<Text>().text = i.ToString();
  249. obj.transform.GetChild(1).GetComponent<Text>().text = plan.from;
  250. obj.transform.GetChild(2).GetComponent<Text>().text = plan.to;
  251. obj.transform.GetChild(3).GetComponent<Text>().text =
  252. CoordinateConverter.Haversine(plan.fromLttd, plan.fromLong, plan.toLttd, plan.toLong).ToString("0.00") + "km";
  253. obj.transform.GetChild(4).GetComponent<Text>().text = plan.manNum.ToString();
  254. ParticleSystem par1 = GameObject.Instantiate(particle1).GetComponent<ParticleSystem>();
  255. par1.transform.SetParent(moveParentObj.transform);
  256. Vector3 startPos = CoordinateConverter.GeoToUnity(plan.paths[0].longitude, plan.paths[0].latitude);
  257. // 假设 par1 是挂了 ParticleSystem + ParticlePath 的 GameObject
  258. ParticleSystem ps = par1.GetComponent<ParticleSystem>();
  259. ParticlePath pp = par1.GetComponent<ParticlePath>();
  260. // unityPath 是你的 List<Vector3> 路径点
  261. List<Vector3> unityPath = new List<Vector3>();
  262. for (int j = 0; j < plan.paths.Count - 1; j++)
  263. {
  264. var start = plan.paths[j];
  265. Vector3 tempPos = CoordinateConverter.GeoToUnity(start.longitude, start.latitude);
  266. unityPath.Add(tempPos);
  267. }
  268. par1.transform.position = unityPath[0];
  269. pp.InitPath(ps, unityPath, 2, false);
  270. // 6. 激活路径移动
  271. pp.IsApprove = true;
  272. pp.IsPath = true;
  273. }
  274. moveParentObj.gameObject.SetActive(false);
  275. }
  276. private void InitUpLeft()
  277. {
  278. yanmomianjiText.text = $"{GlobalData.schedulingData.data.risk_information.submerged_area} <size=14><color=#A5BFE2>k㎡</color></size>";
  279. yanmogengdiText.text = $"{GlobalData.schedulingData.data.risk_information.submerged_farmland_area} <size=14><color=#A5BFE2>k㎡</color></size>";
  280. yingxiangrenkouText.text = $"{GlobalData.schedulingData.data.risk_information.affected_population} <size=14><color=#A5BFE2>万人</color></size>";
  281. gDPText.text = $"{GlobalData.schedulingData.data.risk_information.submerged_area_gdp} <size=14><color=#A5BFE2>亿元</color></size>";
  282. hongshuisunshiText.text = $"{GlobalData.schedulingData.data.risk_information.flood_loss} <size=14><color=#A5BFE2>亿元</color></size>";
  283. }
  284. private void InitUpRight()
  285. {
  286. for (int i = 0; i < GlobalData.schedulingData.data.personnel_support.Count; i++)
  287. {
  288. GameObject obj = Instantiate(rybzPrefab);
  289. obj.transform.SetParent(rybzContent);
  290. obj.transform.localScale = Vector3.one;
  291. obj.transform.GetChild(0).GetComponent<Text>().text = GlobalData.schedulingData.data.personnel_support[i].id.ToString();
  292. obj.transform.GetChild(1).GetComponent<Text>().text = GlobalData.schedulingData.data.personnel_support[i].person;
  293. obj.transform.GetChild(2).GetComponent<Text>().text = GlobalData.schedulingData.data.personnel_support[i].unit;
  294. obj.transform.GetChild(3).GetComponent<Text>().text = GlobalData.schedulingData.data.personnel_support[i].position.ToString();
  295. obj.transform.GetChild(4).GetComponent<Text>().text = GlobalData.schedulingData.data.personnel_support[i].phone.ToString();
  296. }
  297. }
  298. private void InitDownRight()
  299. {
  300. for (int i = 0; i < GlobalData.schedulingData.data.material_support.Count; i++)
  301. {
  302. GameObject obj = Instantiate(wzbzPrefab);
  303. obj.transform.SetParent(wzbzContent);
  304. obj.transform.localScale = Vector3.one;
  305. obj.transform.GetChild(0).GetComponent<Text>().text = GlobalData.schedulingData.data.material_support[i].id.ToString();
  306. obj.transform.GetChild(1).GetComponent<Text>().text = GlobalData.schedulingData.data.material_support[i].type;
  307. obj.transform.GetChild(2).GetComponent<Text>().text = GlobalData.schedulingData.data.material_support[i].quantity.ToString() + GlobalData.schedulingData.data.material_support[i].unit.ToString();
  308. obj.transform.GetChild(3).GetComponent<Text>().text = GlobalData.schedulingData.data.material_support[i].unit.ToString();
  309. obj.transform.GetChild(4).GetComponent<Text>().text = GlobalData.schedulingData.data.material_support[i].person_in_charge.ToString();
  310. obj.transform.GetChild(5).GetComponent<Text>().text = GlobalData.schedulingData.data.material_support[i].region.ToString();
  311. }
  312. }
  313. public override void OnUILeave()
  314. {
  315. base.OnUILeave();
  316. OnExitXHDDYS();
  317. }
  318. void OnExitXHDDYS()
  319. {
  320. TimeLineControl.instance.transform.GetChild(0).gameObject.SetActive(false);
  321. TimeLineControl.instance.transform.GetChild(1).GetChild(1).localPosition = Vector3.zero;
  322. moveParentObj.gameObject.SetActive(false);
  323. moveParentObj.gameObject.SetActive(false);
  324. qxhddContent.gameObject.SetActive(true);
  325. xhddContent.gameObject.SetActive(false);
  326. inAniamtion = false;
  327. GameObject tkobj = StaticLod.instance.staticImportants[1].gameObject;
  328. tkobj.transform.GetChild(1).GetComponent<Animator>().Play("ZhaMenEmpty");
  329. mask.gameObject.SetActive(false);
  330. playing = false;
  331. yjCTS?.Cancel(); // 立刻终止 async
  332. AllRestore();
  333. }
  334. async void ChangeDDYAContent(AlertInfo alertInfo)
  335. {
  336. fbsjText.text = alertInfo.publishCondition;
  337. hxmbText.text = alertInfo.coreGoal;
  338. for (int i = 0; i < alertInfo.tasks.Count; i++)
  339. {
  340. GameObject obj = Instantiate(titleContentPrefab);
  341. obj.GetComponent<RectTransform>().SetParent(zyrwContent.transform);
  342. obj.GetComponent<RectTransform>().localScale = Vector3.one;
  343. obj.transform.GetChild(0).GetComponent<Text>().text = alertInfo.tasks[i].title;
  344. obj.transform.GetChild(1).GetComponent<Text>().text = alertInfo.tasks[i].items.Replace("\\n","\n");
  345. }
  346. for (int i = 0; i < alertInfo.originalSections.Count; i++)
  347. {
  348. GameObject obj = Instantiate(titleContentPrefab);
  349. obj.GetComponent<RectTransform>().SetParent(zxmxContent.transform);
  350. obj.GetComponent<RectTransform>().localScale = Vector3.one;
  351. obj.transform.GetChild(0).GetComponent<Text>().text = alertInfo.originalSections[i].title;
  352. obj.transform.GetChild(1).GetComponent<Text>().text = alertInfo.originalSections[i].content.Replace("\\n", "\n");
  353. }
  354. await new WaitForFixedUpdate();
  355. LayoutRebuilder.ForceRebuildLayoutImmediate(fbsjText.transform.parent.GetComponent<RectTransform>()); // 强制重新计算布局
  356. LayoutRebuilder.ForceRebuildLayoutImmediate(zyrwContent.GetComponent<RectTransform>()); // 强制重新计算布局
  357. LayoutRebuilder.ForceRebuildLayoutImmediate(hxmbText.transform.parent.GetComponent<RectTransform>()); // 强制重新计算布局
  358. LayoutRebuilder.ForceRebuildLayoutImmediate(zxmxContent.GetComponent<RectTransform>()); // 强制重新计算布局
  359. }
  360. public int yAIndex = 0;
  361. void ChangeXHDDYA1(YJType type)
  362. {
  363. for (int i = zyrwContent.transform.childCount - 1; i >= 0; i--)
  364. {
  365. Destroy(zyrwContent.transform.GetChild(i).gameObject);
  366. }
  367. for (int i = zxmxContent.transform.childCount - 1; i >= 0; i--)
  368. {
  369. Destroy(zxmxContent.transform.GetChild(i).gameObject);
  370. }
  371. switch (type)
  372. {
  373. case YJType.BLUE:
  374. yjTitle.text = "蓝色预警";
  375. ChangeDDYAContent(GlobalData.xHDDAllDatas[yAIndex].allAlert.blueAlert);
  376. break;
  377. case YJType.YELLOW:
  378. yjTitle.text = "黄色预警";
  379. ChangeDDYAContent(GlobalData.xHDDAllDatas[yAIndex].allAlert.yellowAlert);
  380. break;
  381. case YJType.ORANGE:
  382. yjTitle.text = "橙色预警";
  383. ChangeDDYAContent(GlobalData.xHDDAllDatas[yAIndex].allAlert.orangeAlert);
  384. break;
  385. case YJType.RED:
  386. yjTitle.text = "红色预警";
  387. ChangeDDYAContent(GlobalData.xHDDAllDatas[yAIndex].allAlert.redAlert);
  388. break;
  389. }
  390. }
  391. void ChangeXHDDYA2()
  392. {
  393. for (int i = yrzzContent.transform.childCount - 1; i >= 0; i--)
  394. {
  395. Destroy(yrzzContent.transform.GetChild(i).gameObject);
  396. }
  397. for (int i = 0; i < GlobalData.xHDDAllDatas[yAIndex].rkzyld.Count; i++)
  398. {
  399. GameObject obj = Instantiate(g0);
  400. obj.GetComponent<RectTransform>().SetParent(yrzzContent.transform);
  401. obj.GetComponent<RectTransform>().localScale = Vector3.one;
  402. obj.transform.GetChild(0).GetChild(0).GetComponent<Text>().text = GlobalData.xHDDAllDatas[yAIndex].rkzyld[i].unit;
  403. obj.transform.GetChild(0).GetChild(1).GetComponent<Text>().text = GlobalData.xHDDAllDatas[yAIndex].rkzyld[i].position;
  404. obj.transform.GetChild(0).GetChild(2).GetComponent<Text>().text = GlobalData.xHDDAllDatas[yAIndex].rkzyld[i].name;
  405. obj.transform.GetChild(0).GetChild(3).GetComponent<Text>().text = GlobalData.xHDDAllDatas[yAIndex].rkzyld[i].phone;
  406. obj.transform.GetChild(1).GetChild(1).GetComponent<Text>().text = GlobalData.xHDDAllDatas[yAIndex].rkzyld[i].responsibility;
  407. }
  408. }
  409. void ChangeXHDDYA3()
  410. {
  411. for (int i = xgxzContent.transform.childCount - 1; i >= 0; i--)
  412. {
  413. Destroy(xgxzContent.transform.GetChild(i).gameObject);
  414. }
  415. if (GlobalData.xHDDAllDatas[yAIndex].rkzygb.Count < 1)
  416. return;
  417. for (int i = 0; i < GlobalData.xHDDAllDatas[yAIndex].rkzygb[0].members.Count; i++)
  418. {
  419. GameObject obj = Instantiate(g1);
  420. obj.GetComponent<RectTransform>().SetParent(xgxzContent.transform);
  421. obj.GetComponent<RectTransform>().localScale = Vector3.one;
  422. obj.transform.GetChild(0).GetComponent<Text>().text = GlobalData.xHDDAllDatas[yAIndex].rkzygb[0].members[i].village;
  423. obj.transform.GetChild(1).GetComponent<Text>().text = GlobalData.xHDDAllDatas[yAIndex].rkzygb[0].members[i].position;
  424. obj.transform.GetChild(2).GetComponent<Text>().text = GlobalData.xHDDAllDatas[yAIndex].rkzygb[0].members[i].name;
  425. obj.transform.GetChild(3).GetComponent<Text>().text = GlobalData.xHDDAllDatas[yAIndex].rkzygb[0].members[i].phone;
  426. }
  427. regionDropdown.ClearOptions();
  428. List<Dropdown.OptionData> dropoptions = new List<Dropdown.OptionData>();
  429. for (int i = 0; i < GlobalData.xHDDAllDatas[yAIndex].rkzygb.Count; i++)
  430. {
  431. dropoptions.Add(new Dropdown.OptionData(GlobalData.xHDDAllDatas[yAIndex].rkzygb[i].region));
  432. }
  433. regionDropdown.AddOptions(dropoptions);
  434. regionDropdown.onValueChanged.RemoveAllListeners();
  435. regionDropdown.onValueChanged.AddListener((int index) =>
  436. {
  437. for (int i = xgxzContent.transform.childCount - 1; i >= 0; i--)
  438. {
  439. Destroy(xgxzContent.transform.GetChild(i).gameObject);
  440. }
  441. for (int i = 0; i < GlobalData.xHDDAllDatas[yAIndex].rkzygb[index].members.Count; i++)
  442. {
  443. GameObject obj = Instantiate(g1);
  444. obj.GetComponent<RectTransform>().SetParent(xgxzContent.transform);
  445. obj.GetComponent<RectTransform>().localScale = Vector3.one;
  446. obj.transform.GetChild(0).GetComponent<Text>().text = GlobalData.xHDDAllDatas[yAIndex].rkzygb[index].members[i].village;
  447. obj.transform.GetChild(1).GetComponent<Text>().text = GlobalData.xHDDAllDatas[yAIndex].rkzygb[index].members[i].position;
  448. obj.transform.GetChild(2).GetComponent<Text>().text = GlobalData.xHDDAllDatas[yAIndex].rkzygb[index].members[i].name;
  449. obj.transform.GetChild(3).GetComponent<Text>().text = GlobalData.xHDDAllDatas[yAIndex].rkzygb[index].members[i].phone;
  450. }
  451. });
  452. }
  453. void InitButton()
  454. {
  455. yjDropdown.ClearOptions();
  456. List<Dropdown.OptionData> dropoptions = new List<Dropdown.OptionData>();
  457. for (int i = 0; i < GlobalData.xHDDAllDatas.Count; i++)
  458. {
  459. dropoptions.Add(new Dropdown.OptionData(GlobalData.xHDDAllDatas[i].title));
  460. }
  461. yjDropdown.AddOptions(dropoptions);
  462. yjDropdown.onValueChanged.AddListener((int index) =>
  463. {
  464. yAIndex = index;
  465. ChangeXHDDYA1(yJType);
  466. ChangeXHDDYA2();
  467. ChangeXHDDYA3();
  468. });
  469. enterBtn.onClick.AddListener(() =>
  470. {
  471. qxhddContent.gameObject.SetActive(false);
  472. xhddContent.gameObject.SetActive(true);
  473. inAniamtion = true;
  474. for (int j = 0; j < yjButtons.Length; j++)
  475. {
  476. yjButtons[j].GetComponent<CanvasGroup>().alpha = 0.2f;
  477. }
  478. yjButtons[0].GetComponent<CanvasGroup>().alpha = 1f;
  479. yJType = YJType.BLUE;
  480. BeginYJMovie(yJType);
  481. ChangeXHDDYA1(yJType);
  482. ChangeXHDDYA2();
  483. ChangeXHDDYA3();
  484. });
  485. exitBtn.onClick.AddListener(OnExitXHDDYS);
  486. for (int i = 0; i < yjButtons.Length; i++)
  487. {
  488. int temp = i;
  489. yjButtons[i].onClick.AddListener(() =>
  490. {
  491. yJType = (YJType)temp;
  492. BeginYJMovie(yJType);
  493. });
  494. }
  495. }
  496. void BeginYJMovie(YJType yjtype)
  497. {
  498. // 停掉之前的动画
  499. yjCTS?.Cancel();
  500. yjCTS = new CancellationTokenSource();
  501. playing = true;
  502. currentTime = 0f;
  503. for (int j = 0; j < yjButtons.Length; j++)
  504. yjButtons[j].GetComponent<CanvasGroup>().alpha = 0.2f;
  505. yjButtons[(int)yjtype].GetComponent<CanvasGroup>().alpha = 1f;
  506. ChangeXHDDYA1(yjtype);
  507. // 启动新的动画
  508. _ = RunYJAsync(yjtype, yjCTS.Token);
  509. }
  510. void AllRestore()
  511. {
  512. TimeLineControl.instance.transform.GetChild(1).GetChild(1).localPosition = Vector3.zero;
  513. TimeLineControl.instance.transform.GetChild(0).gameObject.SetActive(false);
  514. GameObject.FindGameObjectWithTag("HeMianStatic").transform.GetChild(2).gameObject.SetActive(true);
  515. Material material = TimeLineControl.instance.transform.GetChild(1).GetChild(0).GetComponent<MeshRenderer>().material;
  516. material.SetFloat("_ClipLength", 1);
  517. currentTime = 0;
  518. }
  519. async Task RunYJAsync(YJType yjtype, CancellationToken token)
  520. {
  521. Material material = TimeLineControl.instance
  522. .transform.GetChild(1).GetChild(0)
  523. .GetComponent<MeshRenderer>().material;
  524. material.SetFloat("_ClipLength", 1);
  525. moveParentObj.gameObject.SetActive(false);
  526. TimeLineControl.instance.transform.GetChild(0).gameObject.SetActive(false);
  527. DOTween.Kill("TimeLineMove");
  528. TimeLineControl.instance.transform.GetChild(1).GetChild(1).localPosition = Vector3.zero;
  529. try
  530. {
  531. switch (yjtype)
  532. {
  533. case YJType.BLUE:
  534. await YJ_BLUE(token);
  535. break;
  536. case YJType.YELLOW:
  537. await YJ_YELLOW(token);
  538. break;
  539. case YJType.ORANGE:
  540. await YJ_ORANGE(token);
  541. break;
  542. case YJType.RED:
  543. await YJ_RED(token);
  544. break;
  545. }
  546. }
  547. catch (OperationCanceledException)
  548. {
  549. // 正常取消,什么都不做
  550. }
  551. }
  552. async Task YJ_BLUE(CancellationToken token)
  553. {
  554. TimeLineControl.instance.transform.GetChild(0).gameObject.SetActive(false);
  555. await WaitUntilAsync(() => currentTime > 1, token);
  556. token.ThrowIfCancellationRequested();
  557. StaticLod.instance.OnFoucusStatic("Bird3");
  558. await WaitUntilAsync(() => currentTime > 3, token);
  559. token.ThrowIfCancellationRequested();
  560. TimeLineControl.instance.transform.GetChild(0).gameObject.SetActive(true);
  561. await WaitUntilAsync(() => currentTime > 11, token);
  562. await WaitUntilAsync(() => currentTime > 14, token);
  563. }
  564. async Task YJ_YELLOW(CancellationToken token)
  565. {
  566. TimeLineControl.instance.transform.GetChild(1).GetChild(1).localPosition = Vector3.zero;
  567. await WaitUntilAsync(() => currentTime > 1, token);
  568. token.ThrowIfCancellationRequested();
  569. StaticLod.instance.OnFoucusStatic("Bird1");
  570. await WaitUntilAsync(() => currentTime > 3, token);
  571. token.ThrowIfCancellationRequested();
  572. TimeLineControl.instance.transform.GetChild(1).GetChild(1).DOLocalMove(new Vector3(0, 0, 31.2f), 12f).SetId("TimeLineMove");
  573. await WaitUntilAsync(() => currentTime > 14, token);
  574. token.ThrowIfCancellationRequested();
  575. StaticLod.instance.OnFoucusStatic("Bird2");
  576. await WaitUntilAsync(() => currentTime > 17, token);
  577. token.ThrowIfCancellationRequested();
  578. }
  579. async Task YJ_ORANGE(CancellationToken token)
  580. {
  581. TimeLineControl.instance.transform.GetChild(1).GetChild(1).localPosition = new Vector3(0, 0, 31.2f);
  582. TimeLineControl.instance.transform.GetChild(0).gameObject.SetActive(false);
  583. await WaitUntilAsync(() => currentTime > 1, token);
  584. token.ThrowIfCancellationRequested();
  585. StaticLod.instance.OnFoucusStatic("Bird3");
  586. await WaitUntilAsync(() => currentTime > 3, token);
  587. token.ThrowIfCancellationRequested();
  588. moveParentObj.gameObject.SetActive(true);
  589. await WaitUntilAsync(() => currentTime > 14, token);
  590. }
  591. async Task YJ_RED(CancellationToken token)
  592. {
  593. // 准备阶段
  594. Material material = TimeLineControl.instance
  595. .transform.GetChild(1).GetChild(0)
  596. .GetComponent<MeshRenderer>().material;
  597. TimeLineControl.instance.transform.GetChild(0).gameObject.SetActive(false);
  598. material.SetFloat("_ClipLength", 1);
  599. TimeLineControl.instance.transform.GetChild(1).GetChild(1).localPosition =
  600. new Vector3(0, 0, 31.2f);
  601. // ====== Step 1 ======
  602. await WaitUntilAsync(() => currentTime > 1, token);
  603. token.ThrowIfCancellationRequested();
  604. StaticLod.instance.OnFoucusStatic("Bird2");
  605. // ====== Step 2 ======
  606. await WaitUntilAsync(() => currentTime > 4, token);
  607. token.ThrowIfCancellationRequested();
  608. StaticLod.instance.OnFoucusStatic("Bird4");
  609. GameObject tkobj = StaticLod.instance.staticImportants[1].gameObject;
  610. tkobj.transform.GetChild(1).GetComponent<Animator>().Play("ZhaMen");
  611. // ====== Step 3 ======
  612. await WaitUntilAsync(() => currentTime > 5.2, token);
  613. token.ThrowIfCancellationRequested();
  614. // ====== Step 4 ======
  615. await WaitUntilAsync(() => currentTime > 6.7, token);
  616. token.ThrowIfCancellationRequested();
  617. StaticLod.instance.OnFoucusStatic("Bird5");
  618. CameraManager.instance.mainCamera.GetComponent<CameraBird>().target
  619. .DOLocalMoveX(2650, 7.0f);
  620. // ====== Step 5 ======
  621. await WaitUntilAsync(() => currentTime > 14.7, token);
  622. token.ThrowIfCancellationRequested();
  623. material.SetFloat("_ClipLength", 1f);
  624. DOTween.To(() => material.GetFloat("_ClipLength"),
  625. x => material.SetFloat("_ClipLength", x),
  626. 0.981f, 2f);
  627. // ====== Step 6 ======
  628. await WaitUntilAsync(() => currentTime > 15.7, token);
  629. token.ThrowIfCancellationRequested();
  630. DOTween.To(() => material.GetFloat("_ClipLength"),
  631. x => material.SetFloat("_ClipLength", x),
  632. 0.881f, 4f);
  633. // ====== Step 7 ======
  634. await WaitUntilAsync(() => currentTime > 20.7, token);
  635. token.ThrowIfCancellationRequested();
  636. StaticLod.instance.OnFoucusStatic("Bird3");
  637. DOTween.To(() => material.GetFloat("_ClipLength"),
  638. x => material.SetFloat("_ClipLength", x),
  639. 0.1f, 6f);
  640. // ====== Step 8 ======
  641. await WaitUntilAsync(() => currentTime > 26.7, token);
  642. token.ThrowIfCancellationRequested();
  643. mask.gameObject.SetActive(false);
  644. }
  645. async Task WaitUntilAsync(Func<bool> condition, CancellationToken token)
  646. {
  647. while (!condition())
  648. {
  649. token.ThrowIfCancellationRequested();
  650. await Task.Yield();
  651. }
  652. }
  653. // Update is called once per frame
  654. void Update()
  655. {
  656. currentTime += Time.deltaTime;
  657. GameObject tkobj = StaticLod.instance.staticImportants[1].gameObject;
  658. tkobj.transform.GetChild(1).gameObject.SetActive(inAniamtion);
  659. tkobj.transform.GetChild(tkobj.transform.childCount - 1).gameObject.SetActive(!inAniamtion);
  660. }
  661. }