Net_FaultFixCtrl.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  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. public enum Net_FaultQuestionType
  9. {
  10. select,
  11. trigger
  12. }
  13. public enum Net_FaultType
  14. {
  15. netWorkCard,
  16. lightModel,
  17. router,
  18. exchangeBoard,
  19. none,
  20. }
  21. public struct NetStepItemTriggerData
  22. {
  23. public Net_FaultQuestionType questionType;
  24. public Net_FaultType faultType; //如果是选择题的话选择对应错误
  25. public UI_TriggerItemType item_1;
  26. public UI_TriggerItemType item_2;
  27. public float timeLineStart;
  28. public float timeLineEnd;
  29. }
  30. public class Net_FaultFixCtrl : MonoBehaviour
  31. {
  32. public PlayableDirector networkCardLine;
  33. public PlayableDirector lightModelTimeLine;
  34. //步骤统计
  35. private int currentStepIndex = 0;
  36. private Net_FaultType currentType = Net_FaultType.none;
  37. private List<NetStepItemTriggerData> netWorkCardStepList;
  38. private List<NetStepItemTriggerData> lightModelStepList;
  39. private void Awake()
  40. {
  41. InitNetWorkCardStep();
  42. InitLightModelStep();
  43. }
  44. private void Start()
  45. {
  46. GameMain.Event.Subscribe(UI_ItemMoveDoneEvent.EventId, OnGetUI_ItemMoveDone);
  47. GameMain.Event.Subscribe(Net_SelectFaultItemEvent.EventId, OnGetSelectFaultItem);
  48. GameMain.Event.Subscribe(Net_FaultStartEvent.EventId, OnGetNet_FaultStart);
  49. }
  50. private void OnDestroy()
  51. {
  52. if (GameMain.Event.Check(UI_ItemMoveDoneEvent.EventId, OnGetUI_ItemMoveDone))
  53. {
  54. GameMain.Event.Unsubscribe(UI_ItemMoveDoneEvent.EventId, OnGetUI_ItemMoveDone);
  55. }
  56. if (GameMain.Event.Check(Net_SelectFaultItemEvent.EventId, OnGetSelectFaultItem))
  57. {
  58. GameMain.Event.Unsubscribe(Net_SelectFaultItemEvent.EventId, OnGetSelectFaultItem);
  59. }
  60. if (GameMain.Event.Check(Net_FaultStartEvent.EventId, OnGetNet_FaultStart))
  61. {
  62. GameMain.Event.Unsubscribe(Net_FaultStartEvent.EventId, OnGetNet_FaultStart);
  63. }
  64. }
  65. private void InitNetWorkCardStep()
  66. {
  67. netWorkCardStepList = new List<NetStepItemTriggerData>();
  68. //1 选择更换网卡
  69. netWorkCardStepList.Add(new NetStepItemTriggerData()
  70. {
  71. questionType = Net_FaultQuestionType.select,
  72. faultType = Net_FaultType.netWorkCard,
  73. item_1 = UI_TriggerItemType.none,
  74. item_2 = UI_TriggerItemType.none,
  75. timeLineStart = 16.1f,
  76. timeLineEnd = -1
  77. });
  78. //2 合成手套
  79. netWorkCardStepList.Add(new NetStepItemTriggerData()
  80. {
  81. questionType = Net_FaultQuestionType.trigger,
  82. faultType = Net_FaultType.netWorkCard,
  83. item_1 = UI_TriggerItemType.hand,
  84. item_2 = UI_TriggerItemType.gloves,
  85. timeLineStart = 48,
  86. timeLineEnd = -1
  87. });
  88. //3 拆机箱盖
  89. netWorkCardStepList.Add(new NetStepItemTriggerData()
  90. {
  91. questionType = Net_FaultQuestionType.trigger,
  92. faultType = Net_FaultType.netWorkCard,
  93. item_1 = UI_TriggerItemType.handWithGloves,
  94. item_2 = UI_TriggerItemType.chassisCover,
  95. timeLineStart = 48,
  96. timeLineEnd = 52
  97. });
  98. //4 螺丝刀拆网卡
  99. netWorkCardStepList.Add(new NetStepItemTriggerData()
  100. {
  101. questionType = Net_FaultQuestionType.trigger,
  102. faultType = Net_FaultType.netWorkCard,
  103. item_1 = UI_TriggerItemType.screwdriver,
  104. item_2 = UI_TriggerItemType.netWorkCard,
  105. timeLineStart = 52,
  106. timeLineEnd = 62
  107. });
  108. //5 插上新网卡
  109. netWorkCardStepList.Add(new NetStepItemTriggerData()
  110. {
  111. questionType = Net_FaultQuestionType.trigger,
  112. faultType = Net_FaultType.netWorkCard,
  113. item_1 = UI_TriggerItemType.netWorkCard,
  114. item_2 = UI_TriggerItemType.netWorkCardSetPos,
  115. timeLineStart = 84,
  116. timeLineEnd = 88
  117. });
  118. //6 拧紧螺丝
  119. netWorkCardStepList.Add(new NetStepItemTriggerData()
  120. {
  121. questionType = Net_FaultQuestionType.trigger,
  122. faultType = Net_FaultType.netWorkCard,
  123. item_1 = UI_TriggerItemType.screwdriver,
  124. item_2 = UI_TriggerItemType.netWorkCard,
  125. timeLineStart = 88,
  126. timeLineEnd = 96
  127. });
  128. //7 盖上盖子
  129. netWorkCardStepList.Add(new NetStepItemTriggerData()
  130. {
  131. questionType = Net_FaultQuestionType.trigger,
  132. faultType = Net_FaultType.netWorkCard,
  133. item_1 = UI_TriggerItemType.chassisCover,
  134. item_2 = UI_TriggerItemType.chassisCoverSetPos,
  135. timeLineStart = 97,
  136. timeLineEnd = 100
  137. });
  138. }
  139. private void InitLightModelStep()
  140. {
  141. lightModelStepList = new List<NetStepItemTriggerData>();
  142. //1 选择更换光模块
  143. lightModelStepList.Add(new NetStepItemTriggerData()
  144. {
  145. questionType = Net_FaultQuestionType.select,
  146. faultType = Net_FaultType.lightModel,
  147. item_1 = UI_TriggerItemType.none,
  148. item_2 = UI_TriggerItemType.none,
  149. timeLineStart = 19,
  150. timeLineEnd = -1
  151. });
  152. //2 合成手套
  153. lightModelStepList.Add(new NetStepItemTriggerData()
  154. {
  155. questionType = Net_FaultQuestionType.trigger,
  156. faultType = Net_FaultType.lightModel,
  157. item_1 = UI_TriggerItemType.hand,
  158. item_2 = UI_TriggerItemType.gloves,
  159. timeLineStart = 19,
  160. timeLineEnd = -1
  161. });
  162. //3 拔出光纤
  163. lightModelStepList.Add(new NetStepItemTriggerData()
  164. {
  165. questionType = Net_FaultQuestionType.trigger,
  166. faultType = Net_FaultType.lightModel,
  167. item_1 = UI_TriggerItemType.handWithGloves,
  168. item_2 = UI_TriggerItemType.opticalFiber,
  169. timeLineStart = 20,
  170. timeLineEnd = 24
  171. });
  172. //4 拔出光模块
  173. lightModelStepList.Add(new NetStepItemTriggerData()
  174. {
  175. questionType = Net_FaultQuestionType.trigger,
  176. faultType = Net_FaultType.lightModel,
  177. item_1 = UI_TriggerItemType.handWithGloves,
  178. item_2 = UI_TriggerItemType.lightModel,
  179. timeLineStart = 25,
  180. timeLineEnd = 29
  181. });
  182. //5 更换光模块
  183. lightModelStepList.Add(new NetStepItemTriggerData()
  184. {
  185. questionType = Net_FaultQuestionType.trigger,
  186. faultType = Net_FaultType.lightModel,
  187. item_1 = UI_TriggerItemType.lightModel,
  188. item_2 = UI_TriggerItemType.lightModelSetPos,
  189. timeLineStart = 38,
  190. timeLineEnd = 40
  191. });
  192. //6 插入光纤
  193. lightModelStepList.Add(new NetStepItemTriggerData()
  194. {
  195. questionType = Net_FaultQuestionType.trigger,
  196. faultType = Net_FaultType.lightModel,
  197. item_1 = UI_TriggerItemType.opticalFiber,
  198. item_2 = UI_TriggerItemType.lightModel,
  199. timeLineStart = 47,
  200. timeLineEnd = 50
  201. });
  202. }
  203. private void ReSetFaultFix()
  204. {
  205. currentStepIndex = 0;
  206. if (currentType == Net_FaultType.netWorkCard)
  207. {
  208. networkCardLine.Stop();
  209. networkCardLine.time = netWorkCardStepList[0].timeLineStart;
  210. }
  211. if (currentType == Net_FaultType.lightModel)
  212. {
  213. lightModelTimeLine.Stop();
  214. lightModelTimeLine.time = lightModelStepList[0].timeLineStart;
  215. }
  216. }
  217. private async void OnGetNet_FaultStart(object sender, GameEventArgs e)
  218. {
  219. Net_FaultStartEvent args = (Net_FaultStartEvent)e;
  220. if (args.type == Net_FaultType.netWorkCard && currentType != Net_FaultType.netWorkCard)
  221. {
  222. currentType = Net_FaultType.netWorkCard;
  223. currentStepIndex = 0;
  224. lightModelTimeLine.Stop();
  225. lightModelTimeLine.gameObject.SetActive(false);
  226. networkCardLine.gameObject.SetActive(true);
  227. networkCardLine.time = netWorkCardStepList[0].timeLineStart;
  228. networkCardLine.Play();
  229. await Task.Delay(50);
  230. networkCardLine.Pause();
  231. GameMain.Event.Fire(this, Net_FaultNextEvent.Create(currentType, currentStepIndex));
  232. }
  233. if (args.type == Net_FaultType.lightModel && currentType != Net_FaultType.lightModel)
  234. {
  235. currentType = Net_FaultType.lightModel;
  236. currentStepIndex = 0;
  237. networkCardLine.Stop();
  238. networkCardLine.gameObject.SetActive(false);
  239. lightModelTimeLine.gameObject.SetActive(true);
  240. lightModelTimeLine.time = lightModelStepList[0].timeLineStart;
  241. lightModelTimeLine.Play();
  242. await Task.Delay(50);
  243. lightModelTimeLine.Pause();
  244. GameMain.Event.Fire(this, Net_FaultNextEvent.Create(currentType, currentStepIndex));
  245. }
  246. }
  247. private async void OnGetUI_ItemMoveDone(object sender, GameEventArgs e)
  248. {
  249. List<NetStepItemTriggerData> currentList = null;
  250. int stepCount = -1;
  251. PlayableDirector currentPlayableDirector = null;
  252. switch (currentType)
  253. {
  254. case Net_FaultType.netWorkCard:
  255. currentList = netWorkCardStepList;
  256. stepCount = currentList.Count;
  257. currentPlayableDirector = networkCardLine;
  258. break;
  259. case Net_FaultType.lightModel:
  260. currentList = lightModelStepList;
  261. stepCount = currentList.Count;
  262. currentPlayableDirector = lightModelTimeLine;
  263. break;
  264. }
  265. if (currentList[currentStepIndex].questionType == Net_FaultQuestionType.trigger)
  266. {
  267. UI_ItemMoveDoneEvent args = (UI_ItemMoveDoneEvent)e;
  268. Debug.Log($"{args.item_1}:{args.item_2} {currentList[currentStepIndex].item_1}:{currentList[currentStepIndex].item_2}");
  269. bool pass = false;
  270. if (args.item_1 == currentList[currentStepIndex].item_1)
  271. {
  272. if (args.item_2 == currentList[currentStepIndex].item_2)
  273. {
  274. pass = true;
  275. }
  276. }
  277. else if (args.item_2 == currentList[currentStepIndex].item_1)
  278. {
  279. if (args.item_1 == currentList[currentStepIndex].item_2)
  280. {
  281. pass = true;
  282. }
  283. }
  284. if (pass)
  285. {
  286. if (currentList[currentStepIndex].timeLineEnd != -1)
  287. {
  288. currentPlayableDirector.Play();
  289. await Task.Delay((int)(currentList[currentStepIndex].timeLineEnd -
  290. currentList[currentStepIndex].timeLineStart) * 1000);
  291. currentPlayableDirector.Pause();
  292. }
  293. currentStepIndex++;
  294. if (currentStepIndex >= stepCount)
  295. {
  296. GameMain.Event.Fire(this, IT_TrainStudyDoneEvent.Create());
  297. }
  298. else
  299. {
  300. //todo nextStep
  301. currentPlayableDirector.time = currentList[currentStepIndex].timeLineStart;
  302. currentPlayableDirector.Play();
  303. await Task.Delay(50);
  304. currentPlayableDirector.Pause();
  305. //Debug.Log($"{currentType} {currentStepIndex}");
  306. GameMain.Event.Fire(this, Net_FaultNextEvent.Create(currentType, currentStepIndex));
  307. }
  308. }
  309. }
  310. }
  311. private async void OnGetSelectFaultItem(object sender, GameEventArgs e)
  312. {
  313. List<NetStepItemTriggerData> currentList = null;
  314. int stepCount = -1;
  315. PlayableDirector currentPlayableDirector=null;
  316. switch (currentType)
  317. {
  318. case Net_FaultType.netWorkCard:
  319. currentList = netWorkCardStepList;
  320. stepCount = currentList.Count;
  321. currentPlayableDirector = networkCardLine;
  322. break;
  323. case Net_FaultType.lightModel:
  324. currentList = lightModelStepList;
  325. stepCount = currentList.Count;
  326. currentPlayableDirector = lightModelTimeLine;
  327. break;
  328. }
  329. if (currentList[currentStepIndex].questionType == Net_FaultQuestionType.select)
  330. {
  331. Net_SelectFaultItemEvent args = (Net_SelectFaultItemEvent)e;
  332. if (args.faultType == currentList[currentStepIndex].faultType)
  333. {
  334. if (currentList[currentStepIndex].timeLineEnd != -1)
  335. {
  336. currentPlayableDirector.Play();
  337. await Task.Delay((int)(currentList[currentStepIndex].timeLineEnd-currentList[currentStepIndex].timeLineStart)*1000);
  338. currentPlayableDirector.Pause();
  339. }
  340. currentStepIndex++;
  341. if (currentStepIndex >= stepCount)
  342. {
  343. //todo 完成
  344. }
  345. else
  346. {
  347. //todo nextStep
  348. currentPlayableDirector.time = currentList[currentStepIndex].timeLineStart;
  349. currentPlayableDirector.Play();
  350. await Task.Delay(50);
  351. currentPlayableDirector.Pause();
  352. Debug.Log($"{currentType} {currentStepIndex}");
  353. GameMain.Event.Fire(this,Net_FaultNextEvent.Create(currentType,currentStepIndex));
  354. }
  355. }
  356. }
  357. }
  358. }