XHDDLayer.cs 26 KB

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