XHDDLayer.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. using DG.Tweening;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Threading.Tasks;
  5. using UnityAsync;
  6. using UnityEngine;
  7. using UnityEngine.UI;
  8. using WaitUntil = UnityAsync.WaitUntil;
  9. [System.Serializable]
  10. public enum YJType {
  11. YELLOW,
  12. ORANGE,
  13. RED
  14. }
  15. public class XHDDLayer : YZTRootLayer
  16. {
  17. public RectTransform qxhddContent;
  18. public RectTransform xhddContent;
  19. public Button enterBtn;
  20. public Button exitBtn;
  21. public Button playBtn;
  22. public List<Text> threeStepBtns = new List<Text>();
  23. public Dropdown yjDropdown;
  24. public Button[] yjButtons;
  25. public YJType yJType;
  26. public string[,] allYAContent = new string[3, 3];
  27. bool playing = false;
  28. float currentTime = 0;
  29. // Start is called before the first frame update
  30. void Start()
  31. {
  32. InitYAContent();
  33. InitButton();
  34. }
  35. private void OnEnable()
  36. {
  37. CameraManager.SwitchCamera(0);
  38. StaticLod.instance.OnFoucusStatic(1);
  39. }
  40. public override void OnUILeave()
  41. {
  42. base.OnUILeave();
  43. AllRestore();
  44. }
  45. void InitYAContent() {
  46. allYAContent[0, 0] = "当预报洪水将达到或超过蓄滞洪区启用标准时(套口进洪闸的设防水位为32m),发布黄色预警,做好运用准备。";
  47. allYAContent[0, 1] = "分洪前线指挥部及其下设七个责任组责任人和成员迅速进入运用准备状态,服从前指的统一调度。";
  48. allYAContent[0, 2] = "分蓄洪区内各个乡镇、村组确定1名领导专门负责承担警报发布和传递任务。警报一经发布,各项避洪工作必须迅速及时,不得有误。";
  49. allYAContent[1, 0] = "当需要区内人员转移时,发布橙色预警,开始实施分蓄洪区内居民转移、清场等工作。";
  50. allYAContent[1, 1] = "人员转移时机根据荆江河段及城陵矶附近地区实时水情、防洪工程情况和区内人员转移所需时间等确定。";
  51. allYAContent[1, 2] = "采取电视、广播、电话、传真、汽笛、敲锣、挂旗、报警器、鸣枪或挨户通知等一切可能的形式迅速向分洪区传播分洪转移命令。";
  52. allYAContent[2, 0] = "当决定启用蓄滞洪区时,发布红色警报。";
  53. allYAContent[2, 1] = "开启套口进洪闸或实施上车湾口门爆破,开始分蓄洪。";
  54. allYAContent[2, 2] = "红色警报期持续至具备返迁条件时为止。";
  55. }
  56. void InitButton() {
  57. enterBtn.onClick.AddListener(() =>
  58. {
  59. qxhddContent.gameObject.SetActive(false);
  60. xhddContent.gameObject.SetActive(true);
  61. });
  62. exitBtn.onClick.AddListener(() =>
  63. {
  64. qxhddContent.gameObject.SetActive(true);
  65. xhddContent.gameObject.SetActive(false);
  66. playBtn.interactable = true;
  67. playing = false;
  68. AllRestore();
  69. });
  70. for (int i = 0; i < yjButtons.Length; i++) {
  71. int temp = i;
  72. yjButtons[i].onClick.AddListener(() =>
  73. {
  74. if (!playing) {
  75. ClearAllText();
  76. }
  77. for (int j = 0; j < yjButtons.Length; j++) {
  78. yjButtons[j].GetComponent<CanvasGroup>().alpha = 0.2f;
  79. }
  80. yjButtons[temp].GetComponent<CanvasGroup>().alpha = 1f;
  81. yJType = (YJType)temp;
  82. yjDropdown.value = temp;
  83. });
  84. }
  85. playBtn.onClick.AddListener(() =>
  86. {
  87. ClearAllText();
  88. playing = true;
  89. playBtn.interactable = false;
  90. currentTime = 0;
  91. ControlYJ();
  92. });
  93. }
  94. void AllRestore() {
  95. TimeLineControl.instance.transform.GetChild(1).GetChild(1).localPosition = Vector3.zero;
  96. TimeLineControl.instance.transform.GetChild(0).gameObject.SetActive(false);
  97. Material material = TimeLineControl.instance.transform.GetChild(1).GetChild(0).GetComponent<MeshRenderer>().material;
  98. material.SetFloat("_ClipLength", 1);
  99. currentTime = 0;
  100. }
  101. void ClearAllText() {
  102. for (int i = 0; i < threeStepBtns.Count; i++) {
  103. threeStepBtns[i].text = "";
  104. }
  105. }
  106. async void ControlYJ() {
  107. switch (yJType) {
  108. case YJType.YELLOW:
  109. TimeLineControl.instance.transform.GetChild(1).GetChild(1).localPosition = Vector3.zero;
  110. threeStepBtns[0].text = allYAContent[(int)yJType, 0];
  111. await new WaitUntil(() =>
  112. {
  113. return currentTime > 1;
  114. });
  115. if (!playing) {
  116. playBtn.interactable = true;
  117. return;
  118. }
  119. StaticLod.instance.OnFoucusStatic("Bird1");
  120. await new WaitUntil(() =>
  121. {
  122. return currentTime > 3;
  123. });
  124. if (!playing)
  125. {
  126. playBtn.interactable = true;
  127. return;
  128. }
  129. TimeLineControl.instance.transform.GetChild(1).GetChild(1).DOLocalMove(new Vector3(0, 0, 31.2f), 12.0f);
  130. await new WaitUntil(() =>
  131. {
  132. return currentTime > 14;
  133. });
  134. if (!playing)
  135. {
  136. playBtn.interactable = true;
  137. return;
  138. }
  139. threeStepBtns[1].text = allYAContent[(int)yJType, 1];
  140. StaticLod.instance.OnFoucusStatic("Bird2");
  141. await new WaitUntil(() =>
  142. {
  143. return currentTime > 17;
  144. });
  145. if (!playing)
  146. {
  147. playBtn.interactable = true;
  148. return;
  149. }
  150. threeStepBtns[2].text = allYAContent[(int)yJType, 2];
  151. playBtn.interactable = true;
  152. break;
  153. case YJType.ORANGE:
  154. TimeLineControl.instance.transform.GetChild(1).GetChild(1).localPosition = new Vector3(0, 0, 31.2f);
  155. TimeLineControl.instance.transform.GetChild(0).gameObject.SetActive(false);
  156. threeStepBtns[0].text = allYAContent[(int)yJType, 0];
  157. await new WaitUntil(() =>
  158. {
  159. return currentTime > 1;
  160. });
  161. if (!playing)
  162. {
  163. playBtn.interactable = true;
  164. return;
  165. }
  166. StaticLod.instance.OnFoucusStatic("Bird2");
  167. await new WaitUntil(() =>
  168. {
  169. return currentTime > 3;
  170. });
  171. if (!playing)
  172. {
  173. playBtn.interactable = true;
  174. return;
  175. }
  176. TimeLineControl.instance.transform.GetChild(0).gameObject.SetActive(true);
  177. await new WaitUntil(() =>
  178. {
  179. return currentTime > 11;
  180. });
  181. if (!playing)
  182. {
  183. playBtn.interactable = true;
  184. return;
  185. }
  186. threeStepBtns[1].text = allYAContent[(int)yJType, 1];
  187. StaticLod.instance.OnFoucusStatic("Bird3");
  188. await new WaitUntil(() =>
  189. {
  190. return currentTime > 14;
  191. });
  192. if (!playing)
  193. {
  194. playBtn.interactable = true;
  195. return;
  196. }
  197. threeStepBtns[2].text = allYAContent[(int)yJType, 2];
  198. playBtn.interactable = true;
  199. break;
  200. case YJType.RED:
  201. Material material = TimeLineControl.instance.transform.GetChild(1).GetChild(0).GetComponent<MeshRenderer>().material;
  202. TimeLineControl.instance.transform.GetChild(0).gameObject.SetActive(false);
  203. material.SetFloat("_ClipLength", 1);
  204. TimeLineControl.instance.transform.GetChild(1).GetChild(1).localPosition = new Vector3(0, 0, 31.2f);
  205. TimeLineControl.instance.transform.GetChild(2).GetChild(0).gameObject.SetActive(false);
  206. threeStepBtns[0].text = allYAContent[(int)yJType, 0];
  207. await new WaitUntil(() =>
  208. {
  209. return currentTime > 1;
  210. });
  211. if (!playing)
  212. {
  213. playBtn.interactable = true;
  214. return;
  215. }
  216. StaticLod.instance.OnFoucusStatic("Bird2");
  217. await new WaitUntil(() =>
  218. {
  219. return currentTime > 4;
  220. });
  221. if (!playing)
  222. {
  223. playBtn.interactable = true;
  224. return;
  225. }
  226. StaticLod.instance.OnFoucusStatic("Bird4");
  227. ActionInstance._Instance.ModelAni_On?.Invoke();
  228. await new WaitUntil(() =>
  229. {
  230. return currentTime > 5.2;
  231. });
  232. TimeLineControl.instance.transform.GetChild(2).GetChild(0).gameObject.SetActive(true);
  233. if (!playing)
  234. {
  235. playBtn.interactable = true;
  236. return;
  237. }
  238. await new WaitUntil(() =>
  239. {
  240. return currentTime > 5.7;
  241. });
  242. material.SetFloat("_ClipLength", 0.981f);
  243. if (!playing)
  244. {
  245. playBtn.interactable = true;
  246. return;
  247. }
  248. threeStepBtns[1].text = allYAContent[(int)yJType, 1];
  249. await new WaitUntil(() =>
  250. {
  251. return currentTime > 7.7;
  252. });
  253. if (!playing)
  254. {
  255. playBtn.interactable = true;
  256. return;
  257. }
  258. StaticLod.instance.OnFoucusStatic("Bird5");
  259. DOTween.To(() => material.GetFloat("_ClipLength"), x => material.SetFloat("_ClipLength", x), 0.881f, 4f);
  260. await new WaitUntil(() =>
  261. {
  262. return currentTime > 12.7;
  263. });
  264. if (!playing)
  265. {
  266. playBtn.interactable = true;
  267. return;
  268. }
  269. StaticLod.instance.OnFoucusStatic("Bird3");
  270. DOTween.To(() => material.GetFloat("_ClipLength"), x => material.SetFloat("_ClipLength", x), 0.1f, 6f);
  271. await new WaitUntil(() =>
  272. {
  273. return currentTime > 18.7;
  274. });
  275. if (!playing)
  276. {
  277. playBtn.interactable = true;
  278. return;
  279. }
  280. threeStepBtns[2].text = allYAContent[(int)yJType, 2];
  281. playBtn.interactable = true;
  282. break;
  283. }
  284. }
  285. // Update is called once per frame
  286. void Update()
  287. {
  288. currentTime += Time.deltaTime;
  289. }
  290. }