XHDDLayer.cs 11 KB

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