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. 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. LayoutRebuilder.ForceRebuildLayoutImmediate(fbsjText.transform.parent.GetComponent<RectTransform>()); // 强制重新计算布局
  355. LayoutRebuilder.ForceRebuildLayoutImmediate(hxmbText.transform.parent.GetComponent<RectTransform>()); // 强制重新计算布局
  356. LayoutRebuilder.ForceRebuildLayoutImmediate(zyrwContent.GetComponent<RectTransform>()); // 强制重新计算布局
  357. LayoutRebuilder.ForceRebuildLayoutImmediate(zxmxContent.GetComponent<RectTransform>()); // 强制重新计算布局
  358. }
  359. public int yAIndex = 0;
  360. void ChangeXHDDYA1(YJType type)
  361. {
  362. for (int i = zyrwContent.transform.childCount - 1; i >= 0; i--)
  363. {
  364. Destroy(zyrwContent.transform.GetChild(i).gameObject);
  365. }
  366. for (int i = zxmxContent.transform.childCount - 1; i >= 0; i--)
  367. {
  368. Destroy(zxmxContent.transform.GetChild(i).gameObject);
  369. }
  370. switch (type)
  371. {
  372. case YJType.BLUE:
  373. yjTitle.text = "蓝色预警";
  374. ChangeDDYAContent(GlobalData.xHDDAllDatas[yAIndex].allAlert.blueAlert);
  375. break;
  376. case YJType.YELLOW:
  377. yjTitle.text = "黄色预警";
  378. ChangeDDYAContent(GlobalData.xHDDAllDatas[yAIndex].allAlert.yellowAlert);
  379. break;
  380. case YJType.ORANGE:
  381. yjTitle.text = "橙色预警";
  382. ChangeDDYAContent(GlobalData.xHDDAllDatas[yAIndex].allAlert.orangeAlert);
  383. break;
  384. case YJType.RED:
  385. yjTitle.text = "红色预警";
  386. ChangeDDYAContent(GlobalData.xHDDAllDatas[yAIndex].allAlert.redAlert);
  387. break;
  388. }
  389. }
  390. void ChangeXHDDYA2()
  391. {
  392. for (int i = yrzzContent.transform.childCount - 1; i >= 0; i--)
  393. {
  394. Destroy(yrzzContent.transform.GetChild(i).gameObject);
  395. }
  396. for (int i = 0; i < GlobalData.xHDDAllDatas[yAIndex].rkzyld.Count; i++)
  397. {
  398. GameObject obj = Instantiate(g0);
  399. obj.GetComponent<RectTransform>().SetParent(yrzzContent.transform);
  400. obj.GetComponent<RectTransform>().localScale = Vector3.one;
  401. obj.transform.GetChild(0).GetChild(0).GetComponent<Text>().text = GlobalData.xHDDAllDatas[yAIndex].rkzyld[i].unit;
  402. obj.transform.GetChild(0).GetChild(1).GetComponent<Text>().text = GlobalData.xHDDAllDatas[yAIndex].rkzyld[i].position;
  403. obj.transform.GetChild(0).GetChild(2).GetComponent<Text>().text = GlobalData.xHDDAllDatas[yAIndex].rkzyld[i].name;
  404. obj.transform.GetChild(0).GetChild(3).GetComponent<Text>().text = GlobalData.xHDDAllDatas[yAIndex].rkzyld[i].phone;
  405. obj.transform.GetChild(1).GetChild(1).GetComponent<Text>().text = GlobalData.xHDDAllDatas[yAIndex].rkzyld[i].responsibility;
  406. }
  407. }
  408. void ChangeXHDDYA3()
  409. {
  410. for (int i = xgxzContent.transform.childCount - 1; i >= 0; i--)
  411. {
  412. Destroy(xgxzContent.transform.GetChild(i).gameObject);
  413. }
  414. if (GlobalData.xHDDAllDatas[yAIndex].rkzygb.Count < 1)
  415. return;
  416. for (int i = 0; i < GlobalData.xHDDAllDatas[yAIndex].rkzygb[0].members.Count; i++)
  417. {
  418. GameObject obj = Instantiate(g1);
  419. obj.GetComponent<RectTransform>().SetParent(xgxzContent.transform);
  420. obj.GetComponent<RectTransform>().localScale = Vector3.one;
  421. obj.transform.GetChild(0).GetComponent<Text>().text = GlobalData.xHDDAllDatas[yAIndex].rkzygb[0].members[i].village;
  422. obj.transform.GetChild(1).GetComponent<Text>().text = GlobalData.xHDDAllDatas[yAIndex].rkzygb[0].members[i].position;
  423. obj.transform.GetChild(2).GetComponent<Text>().text = GlobalData.xHDDAllDatas[yAIndex].rkzygb[0].members[i].name;
  424. obj.transform.GetChild(3).GetComponent<Text>().text = GlobalData.xHDDAllDatas[yAIndex].rkzygb[0].members[i].phone;
  425. }
  426. regionDropdown.ClearOptions();
  427. List<Dropdown.OptionData> dropoptions = new List<Dropdown.OptionData>();
  428. for (int i = 0; i < GlobalData.xHDDAllDatas[yAIndex].rkzygb.Count; i++)
  429. {
  430. dropoptions.Add(new Dropdown.OptionData(GlobalData.xHDDAllDatas[yAIndex].rkzygb[i].region));
  431. }
  432. regionDropdown.AddOptions(dropoptions);
  433. regionDropdown.onValueChanged.RemoveAllListeners();
  434. regionDropdown.onValueChanged.AddListener((int index) =>
  435. {
  436. for (int i = xgxzContent.transform.childCount - 1; i >= 0; i--)
  437. {
  438. Destroy(xgxzContent.transform.GetChild(i).gameObject);
  439. }
  440. for (int i = 0; i < GlobalData.xHDDAllDatas[yAIndex].rkzygb[index].members.Count; i++)
  441. {
  442. GameObject obj = Instantiate(g1);
  443. obj.GetComponent<RectTransform>().SetParent(xgxzContent.transform);
  444. obj.GetComponent<RectTransform>().localScale = Vector3.one;
  445. obj.transform.GetChild(0).GetComponent<Text>().text = GlobalData.xHDDAllDatas[yAIndex].rkzygb[index].members[i].village;
  446. obj.transform.GetChild(1).GetComponent<Text>().text = GlobalData.xHDDAllDatas[yAIndex].rkzygb[index].members[i].position;
  447. obj.transform.GetChild(2).GetComponent<Text>().text = GlobalData.xHDDAllDatas[yAIndex].rkzygb[index].members[i].name;
  448. obj.transform.GetChild(3).GetComponent<Text>().text = GlobalData.xHDDAllDatas[yAIndex].rkzygb[index].members[i].phone;
  449. }
  450. });
  451. }
  452. void InitButton()
  453. {
  454. yjDropdown.ClearOptions();
  455. List<Dropdown.OptionData> dropoptions = new List<Dropdown.OptionData>();
  456. for (int i = 0; i < GlobalData.xHDDAllDatas.Count; i++)
  457. {
  458. dropoptions.Add(new Dropdown.OptionData(GlobalData.xHDDAllDatas[i].title));
  459. }
  460. yjDropdown.AddOptions(dropoptions);
  461. yjDropdown.onValueChanged.AddListener((int index) =>
  462. {
  463. yAIndex = index;
  464. ChangeXHDDYA1(yJType);
  465. ChangeXHDDYA2();
  466. ChangeXHDDYA3();
  467. });
  468. enterBtn.onClick.AddListener(() =>
  469. {
  470. qxhddContent.gameObject.SetActive(false);
  471. xhddContent.gameObject.SetActive(true);
  472. inAniamtion = true;
  473. for (int j = 0; j < yjButtons.Length; j++)
  474. {
  475. yjButtons[j].GetComponent<CanvasGroup>().alpha = 0.2f;
  476. }
  477. yjButtons[0].GetComponent<CanvasGroup>().alpha = 1f;
  478. yJType = YJType.BLUE;
  479. BeginYJMovie(yJType);
  480. ChangeXHDDYA1(yJType);
  481. ChangeXHDDYA2();
  482. ChangeXHDDYA3();
  483. });
  484. exitBtn.onClick.AddListener(OnExitXHDDYS);
  485. for (int i = 0; i < yjButtons.Length; i++)
  486. {
  487. int temp = i;
  488. yjButtons[i].onClick.AddListener(() =>
  489. {
  490. yJType = (YJType)temp;
  491. BeginYJMovie(yJType);
  492. });
  493. }
  494. }
  495. void BeginYJMovie(YJType yjtype)
  496. {
  497. // 停掉之前的动画
  498. yjCTS?.Cancel();
  499. yjCTS = new CancellationTokenSource();
  500. playing = true;
  501. currentTime = 0f;
  502. for (int j = 0; j < yjButtons.Length; j++)
  503. yjButtons[j].GetComponent<CanvasGroup>().alpha = 0.2f;
  504. yjButtons[(int)yjtype].GetComponent<CanvasGroup>().alpha = 1f;
  505. ChangeXHDDYA1(yjtype);
  506. // 启动新的动画
  507. _ = RunYJAsync(yjtype, yjCTS.Token);
  508. }
  509. void AllRestore()
  510. {
  511. TimeLineControl.instance.transform.GetChild(1).GetChild(1).localPosition = Vector3.zero;
  512. TimeLineControl.instance.transform.GetChild(0).gameObject.SetActive(false);
  513. GameObject.FindGameObjectWithTag("HeMianStatic").transform.GetChild(2).gameObject.SetActive(true);
  514. Material material = TimeLineControl.instance.transform.GetChild(1).GetChild(0).GetComponent<MeshRenderer>().material;
  515. material.SetFloat("_ClipLength", 1);
  516. currentTime = 0;
  517. }
  518. async Task RunYJAsync(YJType yjtype, CancellationToken token)
  519. {
  520. Material material = TimeLineControl.instance
  521. .transform.GetChild(1).GetChild(0)
  522. .GetComponent<MeshRenderer>().material;
  523. material.SetFloat("_ClipLength", 1);
  524. moveParentObj.gameObject.SetActive(false);
  525. TimeLineControl.instance.transform.GetChild(0).gameObject.SetActive(false);
  526. DOTween.Kill("TimeLineMove");
  527. TimeLineControl.instance.transform.GetChild(1).GetChild(1).localPosition = Vector3.zero;
  528. try
  529. {
  530. switch (yjtype)
  531. {
  532. case YJType.BLUE:
  533. await YJ_BLUE(token);
  534. break;
  535. case YJType.YELLOW:
  536. await YJ_YELLOW(token);
  537. break;
  538. case YJType.ORANGE:
  539. await YJ_ORANGE(token);
  540. break;
  541. case YJType.RED:
  542. await YJ_RED(token);
  543. break;
  544. }
  545. }
  546. catch (OperationCanceledException)
  547. {
  548. // 正常取消,什么都不做
  549. }
  550. }
  551. async Task YJ_BLUE(CancellationToken token)
  552. {
  553. TimeLineControl.instance.transform.GetChild(0).gameObject.SetActive(false);
  554. await WaitUntilAsync(() => currentTime > 1, token);
  555. token.ThrowIfCancellationRequested();
  556. StaticLod.instance.OnFoucusStatic("Bird3");
  557. await WaitUntilAsync(() => currentTime > 3, token);
  558. token.ThrowIfCancellationRequested();
  559. TimeLineControl.instance.transform.GetChild(0).gameObject.SetActive(true);
  560. await WaitUntilAsync(() => currentTime > 11, token);
  561. await WaitUntilAsync(() => currentTime > 14, token);
  562. }
  563. async Task YJ_YELLOW(CancellationToken token)
  564. {
  565. TimeLineControl.instance.transform.GetChild(1).GetChild(1).localPosition = Vector3.zero;
  566. await WaitUntilAsync(() => currentTime > 1, token);
  567. token.ThrowIfCancellationRequested();
  568. StaticLod.instance.OnFoucusStatic("Bird1");
  569. await WaitUntilAsync(() => currentTime > 3, token);
  570. token.ThrowIfCancellationRequested();
  571. TimeLineControl.instance.transform.GetChild(1).GetChild(1).DOLocalMove(new Vector3(0, 0, 31.2f), 12f).SetId("TimeLineMove");
  572. await WaitUntilAsync(() => currentTime > 14, token);
  573. token.ThrowIfCancellationRequested();
  574. StaticLod.instance.OnFoucusStatic("Bird2");
  575. await WaitUntilAsync(() => currentTime > 17, token);
  576. token.ThrowIfCancellationRequested();
  577. }
  578. async Task YJ_ORANGE(CancellationToken token)
  579. {
  580. TimeLineControl.instance.transform.GetChild(1).GetChild(1).localPosition = new Vector3(0, 0, 31.2f);
  581. TimeLineControl.instance.transform.GetChild(0).gameObject.SetActive(false);
  582. await WaitUntilAsync(() => currentTime > 1, token);
  583. token.ThrowIfCancellationRequested();
  584. StaticLod.instance.OnFoucusStatic("Bird3");
  585. await WaitUntilAsync(() => currentTime > 3, token);
  586. token.ThrowIfCancellationRequested();
  587. moveParentObj.gameObject.SetActive(true);
  588. await WaitUntilAsync(() => currentTime > 14, token);
  589. }
  590. async Task YJ_RED(CancellationToken token)
  591. {
  592. // 准备阶段
  593. Material material = TimeLineControl.instance
  594. .transform.GetChild(1).GetChild(0)
  595. .GetComponent<MeshRenderer>().material;
  596. TimeLineControl.instance.transform.GetChild(0).gameObject.SetActive(false);
  597. material.SetFloat("_ClipLength", 1);
  598. TimeLineControl.instance.transform.GetChild(1).GetChild(1).localPosition =
  599. new Vector3(0, 0, 31.2f);
  600. // ====== Step 1 ======
  601. await WaitUntilAsync(() => currentTime > 1, token);
  602. token.ThrowIfCancellationRequested();
  603. StaticLod.instance.OnFoucusStatic("Bird2");
  604. // ====== Step 2 ======
  605. await WaitUntilAsync(() => currentTime > 4, token);
  606. token.ThrowIfCancellationRequested();
  607. StaticLod.instance.OnFoucusStatic("Bird4");
  608. GameObject tkobj = StaticLod.instance.staticImportants[1].gameObject;
  609. tkobj.transform.GetChild(1).GetComponent<Animator>().Play("ZhaMen");
  610. // ====== Step 3 ======
  611. await WaitUntilAsync(() => currentTime > 5.2, token);
  612. token.ThrowIfCancellationRequested();
  613. // ====== Step 4 ======
  614. await WaitUntilAsync(() => currentTime > 6.7, token);
  615. token.ThrowIfCancellationRequested();
  616. StaticLod.instance.OnFoucusStatic("Bird5");
  617. CameraManager.instance.mainCamera.GetComponent<CameraBird>().target
  618. .DOLocalMoveX(2650, 7.0f);
  619. // ====== Step 5 ======
  620. await WaitUntilAsync(() => currentTime > 14.7, token);
  621. token.ThrowIfCancellationRequested();
  622. material.SetFloat("_ClipLength", 1f);
  623. DOTween.To(() => material.GetFloat("_ClipLength"),
  624. x => material.SetFloat("_ClipLength", x),
  625. 0.981f, 2f);
  626. // ====== Step 6 ======
  627. await WaitUntilAsync(() => currentTime > 15.7, token);
  628. token.ThrowIfCancellationRequested();
  629. DOTween.To(() => material.GetFloat("_ClipLength"),
  630. x => material.SetFloat("_ClipLength", x),
  631. 0.881f, 4f);
  632. // ====== Step 7 ======
  633. await WaitUntilAsync(() => currentTime > 20.7, token);
  634. token.ThrowIfCancellationRequested();
  635. StaticLod.instance.OnFoucusStatic("Bird3");
  636. DOTween.To(() => material.GetFloat("_ClipLength"),
  637. x => material.SetFloat("_ClipLength", x),
  638. 0.1f, 6f);
  639. // ====== Step 8 ======
  640. await WaitUntilAsync(() => currentTime > 26.7, token);
  641. token.ThrowIfCancellationRequested();
  642. mask.gameObject.SetActive(false);
  643. }
  644. async Task WaitUntilAsync(Func<bool> condition, CancellationToken token)
  645. {
  646. while (!condition())
  647. {
  648. token.ThrowIfCancellationRequested();
  649. await Task.Yield();
  650. }
  651. }
  652. // Update is called once per frame
  653. void Update()
  654. {
  655. currentTime += Time.deltaTime;
  656. GameObject tkobj = StaticLod.instance.staticImportants[1].gameObject;
  657. tkobj.transform.GetChild(1).gameObject.SetActive(inAniamtion);
  658. tkobj.transform.GetChild(tkobj.transform.childCount - 1).gameObject.SetActive(!inAniamtion);
  659. }
  660. }