Cool_FaultFixCtrl.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Threading.Tasks;
  5. using GameFramework.Event;
  6. using UnityEngine;
  7. using UnityEngine.Playables;
  8. using UnityEngine.Serialization;
  9. public enum Cool_FaultQuestionType
  10. {
  11. select,
  12. trigger
  13. }
  14. public enum Cool_FaultType
  15. {
  16. highPressure,
  17. lowPressure,
  18. airConditioning,
  19. pumpError,
  20. none,
  21. }
  22. public struct CoolStepItemTriggerData
  23. {
  24. public Cool_FaultQuestionType questionType;
  25. public Cool_FaultType faultType; //如果是选择题的话选择对应错误
  26. public UI_TriggerItemType item_1;
  27. public UI_TriggerItemType item_2;
  28. public float timeLineStart;
  29. public float timeLineEnd;
  30. }
  31. public class Cool_FaultFixCtrl : MonoBehaviour
  32. {
  33. public PlayableDirector highPressureTimeLine;
  34. public PlayableDirector lowPressureTimeLine;
  35. public PlayableDirector fault3TimeLine;
  36. //步骤统计
  37. private int currentStepIndex = 0;
  38. private Cool_FaultType currentType = Cool_FaultType.none;
  39. private List<CoolStepItemTriggerData> highPressureStepList;
  40. private List<CoolStepItemTriggerData> lowPressureStepList;
  41. private List<CoolStepItemTriggerData> fault3StepList;
  42. private void Awake()
  43. {
  44. InitHighPressureStep();
  45. InitLowPressureStep();
  46. InitFault3Step();
  47. }
  48. private void Start()
  49. {
  50. GameMain.Event.Subscribe(UI_ItemMoveDoneEvent.EventId, OnGetUI_ItemMoveDone);
  51. GameMain.Event.Subscribe(Cool_SelectFaultItemEvent.EventId, OnGetSelectFaultItem);
  52. GameMain.Event.Subscribe(Cool_FaultStartEvent.EventId, OnGetNet_FaultStart);
  53. }
  54. private void OnDestroy()
  55. {
  56. if (GameMain.Event.Check(UI_ItemMoveDoneEvent.EventId, OnGetUI_ItemMoveDone))
  57. {
  58. GameMain.Event.Unsubscribe(UI_ItemMoveDoneEvent.EventId, OnGetUI_ItemMoveDone);
  59. }
  60. if (GameMain.Event.Check(Cool_SelectFaultItemEvent.EventId, OnGetSelectFaultItem))
  61. {
  62. GameMain.Event.Unsubscribe(Cool_SelectFaultItemEvent.EventId, OnGetSelectFaultItem);
  63. }
  64. if (GameMain.Event.Check(Cool_FaultStartEvent.EventId, OnGetNet_FaultStart))
  65. {
  66. GameMain.Event.Unsubscribe(Cool_FaultStartEvent.EventId, OnGetNet_FaultStart);
  67. }
  68. }
  69. private void InitHighPressureStep()
  70. {
  71. highPressureStepList = new List<CoolStepItemTriggerData>();
  72. //1 选择高压
  73. highPressureStepList.Add(new CoolStepItemTriggerData()
  74. {
  75. questionType = Cool_FaultQuestionType.select,
  76. faultType = Cool_FaultType.highPressure,
  77. item_1 = UI_TriggerItemType.none,
  78. item_2 = UI_TriggerItemType.none,
  79. timeLineStart = 11,
  80. timeLineEnd = -1
  81. });
  82. //2 关闭阀门
  83. highPressureStepList.Add(new CoolStepItemTriggerData()
  84. {
  85. questionType = Cool_FaultQuestionType.trigger,
  86. faultType = Cool_FaultType.highPressure,
  87. item_1 = UI_TriggerItemType.hand,
  88. item_2 = UI_TriggerItemType.valve,
  89. timeLineStart = 24,
  90. timeLineEnd = 26
  91. });
  92. //3 打开盖子
  93. highPressureStepList.Add(new CoolStepItemTriggerData()
  94. {
  95. questionType = Cool_FaultQuestionType.trigger,
  96. faultType = Cool_FaultType.highPressure,
  97. item_1 = UI_TriggerItemType.hand,
  98. item_2 = UI_TriggerItemType.coolCover,
  99. timeLineStart = 30,
  100. timeLineEnd = 32
  101. });
  102. //4 清理管道
  103. highPressureStepList.Add(new CoolStepItemTriggerData()
  104. {
  105. questionType = Cool_FaultQuestionType.trigger,
  106. faultType = Cool_FaultType.highPressure,
  107. item_1 = UI_TriggerItemType.cleaningRod,
  108. item_2 = UI_TriggerItemType.coolCover,
  109. timeLineStart = 34,
  110. timeLineEnd = 45
  111. });
  112. }
  113. private void InitLowPressureStep()
  114. {
  115. lowPressureStepList = new List<CoolStepItemTriggerData>();
  116. //1 选择低压
  117. lowPressureStepList.Add(new CoolStepItemTriggerData()
  118. {
  119. questionType = Cool_FaultQuestionType.select,
  120. faultType = Cool_FaultType.lowPressure,
  121. item_1 = UI_TriggerItemType.none,
  122. item_2 = UI_TriggerItemType.none,
  123. timeLineStart = 13,
  124. timeLineEnd = -1
  125. });
  126. //2 连接冷媒管道
  127. lowPressureStepList.Add(new CoolStepItemTriggerData()
  128. {
  129. questionType = Cool_FaultQuestionType.trigger,
  130. faultType = Cool_FaultType.lowPressure,
  131. item_1 = UI_TriggerItemType.refrigerant,
  132. item_2 = UI_TriggerItemType.refrigerantPos,
  133. timeLineStart = 24,
  134. timeLineEnd = 30
  135. });
  136. //3 打开冷媒阀门
  137. lowPressureStepList.Add(new CoolStepItemTriggerData()
  138. {
  139. questionType = Cool_FaultQuestionType.trigger,
  140. faultType = Cool_FaultType.lowPressure,
  141. item_1 = UI_TriggerItemType.hand,
  142. item_2 = UI_TriggerItemType.refrigerant,
  143. timeLineStart = 30,
  144. timeLineEnd = 38
  145. });
  146. //4 关闭阀门
  147. lowPressureStepList.Add(new CoolStepItemTriggerData()
  148. {
  149. questionType = Cool_FaultQuestionType.trigger,
  150. faultType = Cool_FaultType.lowPressure,
  151. item_1 = UI_TriggerItemType.hand,
  152. item_2 = UI_TriggerItemType.valve,
  153. timeLineStart = 40,
  154. timeLineEnd = 43
  155. });
  156. }
  157. private void InitFault3Step()
  158. {
  159. fault3StepList = new List<CoolStepItemTriggerData>();
  160. //选择安全阀问题
  161. fault3StepList.Add(new CoolStepItemTriggerData()
  162. {
  163. questionType = Cool_FaultQuestionType.select,
  164. faultType = Cool_FaultType.pumpError,
  165. item_1 = UI_TriggerItemType.none,
  166. item_2 = UI_TriggerItemType.none,
  167. timeLineStart = 3,
  168. timeLineEnd = -1
  169. });
  170. //拧下阀门螺丝
  171. fault3StepList.Add(new CoolStepItemTriggerData()
  172. {
  173. questionType = Cool_FaultQuestionType.trigger,
  174. faultType = Cool_FaultType.pumpError,
  175. item_1 = UI_TriggerItemType.hand,
  176. item_2 = UI_TriggerItemType.screw,
  177. timeLineStart = 14,
  178. timeLineEnd = 17
  179. });
  180. //拆开阀座
  181. fault3StepList.Add(new CoolStepItemTriggerData()
  182. {
  183. questionType = Cool_FaultQuestionType.trigger,
  184. faultType = Cool_FaultType.pumpError,
  185. item_1 = UI_TriggerItemType.hand,
  186. item_2 = UI_TriggerItemType.valve,
  187. timeLineStart = 19,
  188. timeLineEnd = 26
  189. });
  190. //清理阀圈
  191. fault3StepList.Add(new CoolStepItemTriggerData()
  192. {
  193. questionType = Cool_FaultQuestionType.trigger,
  194. faultType = Cool_FaultType.pumpError,
  195. item_1 = UI_TriggerItemType.cleaningRod,
  196. item_2 = UI_TriggerItemType.valve,
  197. timeLineStart = 28,
  198. timeLineEnd = 35
  199. });
  200. //装好阀座
  201. fault3StepList.Add(new CoolStepItemTriggerData()
  202. {
  203. questionType = Cool_FaultQuestionType.trigger,
  204. faultType = Cool_FaultType.pumpError,
  205. item_1 = UI_TriggerItemType.hand,
  206. item_2 = UI_TriggerItemType.valve,
  207. timeLineStart = 38,
  208. timeLineEnd = 42
  209. });
  210. //装上螺丝
  211. fault3StepList.Add(new CoolStepItemTriggerData()
  212. {
  213. questionType = Cool_FaultQuestionType.trigger,
  214. faultType = Cool_FaultType.pumpError,
  215. item_1 = UI_TriggerItemType.screw,
  216. item_2 = UI_TriggerItemType.valve,
  217. timeLineStart = 47,
  218. timeLineEnd = 49
  219. });
  220. }
  221. private void ReSetFaultFix()
  222. {
  223. currentStepIndex = 0;
  224. if (currentType == Cool_FaultType.highPressure)
  225. {
  226. highPressureTimeLine.Stop();
  227. highPressureTimeLine.time = highPressureStepList[0].timeLineStart;
  228. }
  229. if (currentType == Cool_FaultType.lowPressure)
  230. {
  231. lowPressureTimeLine.Stop();
  232. lowPressureTimeLine.time = lowPressureStepList[0].timeLineStart;
  233. }
  234. if (currentType == Cool_FaultType.pumpError)
  235. {
  236. fault3TimeLine.Stop();
  237. fault3TimeLine.time = fault3StepList[0].timeLineStart;
  238. }
  239. }
  240. private async void OnGetNet_FaultStart(object sender, GameEventArgs e)
  241. {
  242. Cool_FaultStartEvent args = (Cool_FaultStartEvent)e;
  243. if (args.type == Cool_FaultType.highPressure && currentType != Cool_FaultType.highPressure)
  244. {
  245. currentType = Cool_FaultType.highPressure;
  246. currentStepIndex = 0;
  247. lowPressureTimeLine.Stop();
  248. lowPressureTimeLine.gameObject.SetActive(false);
  249. fault3TimeLine.Stop();
  250. fault3TimeLine.gameObject.SetActive(false);
  251. highPressureTimeLine.gameObject.SetActive(true);
  252. highPressureTimeLine.time = highPressureStepList[0].timeLineStart;
  253. highPressureTimeLine.Play();
  254. await Task.Delay(50);
  255. highPressureTimeLine.Pause();
  256. GameMain.Event.Fire(this, Cool_FaultNextEvent.Create(currentType, currentStepIndex));
  257. }
  258. if (args.type == Cool_FaultType.lowPressure && currentType != Cool_FaultType.lowPressure)
  259. {
  260. currentType = Cool_FaultType.lowPressure;
  261. currentStepIndex = 0;
  262. highPressureTimeLine.Stop();
  263. highPressureTimeLine.gameObject.SetActive(false);
  264. fault3TimeLine.Stop();
  265. fault3TimeLine.gameObject.SetActive(false);
  266. lowPressureTimeLine.gameObject.SetActive(true);
  267. lowPressureTimeLine.time = lowPressureStepList[0].timeLineStart;
  268. lowPressureTimeLine.Play();
  269. await Task.Delay(50);
  270. lowPressureTimeLine.Pause();
  271. GameMain.Event.Fire(this, Cool_FaultNextEvent.Create(currentType, currentStepIndex));
  272. }
  273. if (args.type == Cool_FaultType.pumpError && currentType != Cool_FaultType.pumpError)
  274. {
  275. currentType = Cool_FaultType.pumpError;
  276. currentStepIndex = 0;
  277. highPressureTimeLine.Stop();
  278. highPressureTimeLine.gameObject.SetActive(false);
  279. lowPressureTimeLine.Stop();
  280. lowPressureTimeLine.gameObject.SetActive(false);
  281. fault3TimeLine.gameObject.SetActive(true);
  282. fault3TimeLine.time = fault3StepList[0].timeLineStart;
  283. fault3TimeLine.Play();
  284. await Task.Delay(50);
  285. fault3TimeLine.Pause();
  286. GameMain.Event.Fire(this, Cool_FaultNextEvent.Create(currentType, currentStepIndex));
  287. }
  288. }
  289. private async void OnGetUI_ItemMoveDone(object sender, GameEventArgs e)
  290. {
  291. List<CoolStepItemTriggerData> currentList = null;
  292. int stepCount = -1;
  293. PlayableDirector currentPlayableDirector = null;
  294. switch (currentType)
  295. {
  296. case Cool_FaultType.highPressure:
  297. currentList = highPressureStepList;
  298. stepCount = currentList.Count;
  299. currentPlayableDirector = highPressureTimeLine;
  300. break;
  301. case Cool_FaultType.lowPressure:
  302. currentList = lowPressureStepList;
  303. stepCount = currentList.Count;
  304. currentPlayableDirector = lowPressureTimeLine;
  305. break;
  306. case Cool_FaultType.pumpError:
  307. currentList = fault3StepList;
  308. stepCount = currentList.Count;
  309. currentPlayableDirector = fault3TimeLine;
  310. break;
  311. }
  312. if (currentList[currentStepIndex].questionType == Cool_FaultQuestionType.trigger)
  313. {
  314. UI_ItemMoveDoneEvent args = (UI_ItemMoveDoneEvent)e;
  315. Debug.Log(
  316. $"{args.item_1}:{args.item_2} {currentList[currentStepIndex].item_1}:{currentList[currentStepIndex].item_2}");
  317. bool pass = false;
  318. if (args.item_1 == currentList[currentStepIndex].item_1)
  319. {
  320. if (args.item_2 == currentList[currentStepIndex].item_2)
  321. {
  322. pass = true;
  323. }
  324. }
  325. else if (args.item_2 == currentList[currentStepIndex].item_1)
  326. {
  327. if (args.item_1 == currentList[currentStepIndex].item_2)
  328. {
  329. pass = true;
  330. }
  331. }
  332. if (pass)
  333. {
  334. if (currentList[currentStepIndex].timeLineEnd != -1)
  335. {
  336. currentPlayableDirector.Play();
  337. await Task.Delay((int)(currentList[currentStepIndex].timeLineEnd -
  338. currentList[currentStepIndex].timeLineStart) * 1000);
  339. currentPlayableDirector.Pause();
  340. }
  341. currentStepIndex++;
  342. if (currentStepIndex >= stepCount)
  343. {
  344. GameMain.Event.Fire(this, IT_TrainStudyDoneEvent.Create());
  345. }
  346. else
  347. {
  348. //todo nextStep
  349. currentPlayableDirector.time = currentList[currentStepIndex].timeLineStart;
  350. currentPlayableDirector.Play();
  351. await Task.Delay(50);
  352. currentPlayableDirector.Pause();
  353. Debug.Log($"{currentType} {currentStepIndex}");
  354. GameMain.Event.Fire(this, Cool_FaultNextEvent.Create(currentType, currentStepIndex));
  355. }
  356. }
  357. }
  358. }
  359. private async void OnGetSelectFaultItem(object sender, GameEventArgs e)
  360. {
  361. List<CoolStepItemTriggerData> currentList = null;
  362. int stepCount = -1;
  363. PlayableDirector currentPlayableDirector=null;
  364. switch (currentType)
  365. {
  366. case Cool_FaultType.highPressure:
  367. currentList = highPressureStepList;
  368. stepCount = currentList.Count;
  369. currentPlayableDirector = highPressureTimeLine;
  370. break;
  371. case Cool_FaultType.lowPressure:
  372. currentList = lowPressureStepList;
  373. stepCount = currentList.Count;
  374. currentPlayableDirector = lowPressureTimeLine;
  375. break;
  376. case Cool_FaultType.pumpError:
  377. currentList = fault3StepList;
  378. stepCount = currentList.Count;
  379. currentPlayableDirector = fault3TimeLine;
  380. break;
  381. }
  382. if (currentList[currentStepIndex].questionType == Cool_FaultQuestionType.select)
  383. {
  384. Cool_SelectFaultItemEvent args = (Cool_SelectFaultItemEvent)e;
  385. if (args.faultType == currentList[currentStepIndex].faultType)
  386. {
  387. if (currentList[currentStepIndex].timeLineEnd != -1)
  388. {
  389. currentPlayableDirector.Play();
  390. await Task.Delay((int)(currentList[currentStepIndex].timeLineEnd-currentList[currentStepIndex].timeLineStart)*1000);
  391. currentPlayableDirector.Pause();
  392. }
  393. currentStepIndex++;
  394. if (currentStepIndex >= stepCount)
  395. {
  396. //todo 完成
  397. GameMain.Event.Fire(this, IT_TrainStudyDoneEvent.Create());
  398. }
  399. else
  400. {
  401. //todo nextStep
  402. currentPlayableDirector.time = currentList[currentStepIndex].timeLineStart;
  403. currentPlayableDirector.Play();
  404. await Task.Delay(50);
  405. currentPlayableDirector.Pause();
  406. Debug.Log($"{currentType} {currentStepIndex}");
  407. GameMain.Event.Fire(this,Cool_FaultNextEvent.Create(currentType,currentStepIndex));
  408. }
  409. }
  410. }
  411. }
  412. }