123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Threading.Tasks;
- using GameFramework.Event;
- using UnityEngine;
- using UnityEngine.Playables;
- public enum Net_FaultQuestionType
- {
- select,
- trigger
- }
- public enum Net_FaultType
- {
- netWorkCard,
- lightModel,
- router,
- exchangeBoard,
- none,
- }
- public struct NetStepItemTriggerData
- {
- public Net_FaultQuestionType questionType;
- public Net_FaultType faultType; //如果是选择题的话选择对应错误
- public UI_TriggerItemType item_1;
- public UI_TriggerItemType item_2;
- public float timeLineStart;
- public float timeLineEnd;
- }
- public class Net_FaultFixCtrl : MonoBehaviour
- {
- public PlayableDirector networkCardLine;
- public PlayableDirector lightModelTimeLine;
- //步骤统计
- private int currentStepIndex = 0;
- private Net_FaultType currentType = Net_FaultType.none;
- private List<NetStepItemTriggerData> netWorkCardStepList;
- private List<NetStepItemTriggerData> lightModelStepList;
- private void Awake()
- {
- InitNetWorkCardStep();
- InitLightModelStep();
- }
- private void Start()
- {
- GameMain.Event.Subscribe(UI_ItemMoveDoneEvent.EventId, OnGetUI_ItemMoveDone);
- GameMain.Event.Subscribe(Net_SelectFaultItemEvent.EventId, OnGetSelectFaultItem);
- GameMain.Event.Subscribe(Net_FaultStartEvent.EventId, OnGetNet_FaultStart);
- }
- private void OnDestroy()
- {
- if (GameMain.Event.Check(UI_ItemMoveDoneEvent.EventId, OnGetUI_ItemMoveDone))
- {
- GameMain.Event.Unsubscribe(UI_ItemMoveDoneEvent.EventId, OnGetUI_ItemMoveDone);
- }
- if (GameMain.Event.Check(Net_SelectFaultItemEvent.EventId, OnGetSelectFaultItem))
- {
- GameMain.Event.Unsubscribe(Net_SelectFaultItemEvent.EventId, OnGetSelectFaultItem);
- }
- if (GameMain.Event.Check(Net_FaultStartEvent.EventId, OnGetNet_FaultStart))
- {
- GameMain.Event.Unsubscribe(Net_FaultStartEvent.EventId, OnGetNet_FaultStart);
- }
- }
-
- private void InitNetWorkCardStep()
- {
- netWorkCardStepList = new List<NetStepItemTriggerData>();
- //1 选择更换网卡
- netWorkCardStepList.Add(new NetStepItemTriggerData()
- {
- questionType = Net_FaultQuestionType.select,
- faultType = Net_FaultType.netWorkCard,
- item_1 = UI_TriggerItemType.none,
- item_2 = UI_TriggerItemType.none,
- timeLineStart = 16.1f,
- timeLineEnd = -1
- });
- //2 合成手套
- netWorkCardStepList.Add(new NetStepItemTriggerData()
- {
- questionType = Net_FaultQuestionType.trigger,
- faultType = Net_FaultType.netWorkCard,
- item_1 = UI_TriggerItemType.hand,
- item_2 = UI_TriggerItemType.gloves,
- timeLineStart = 48,
- timeLineEnd = -1
- });
- //3 拆机箱盖
- netWorkCardStepList.Add(new NetStepItemTriggerData()
- {
- questionType = Net_FaultQuestionType.trigger,
- faultType = Net_FaultType.netWorkCard,
- item_1 = UI_TriggerItemType.handWithGloves,
- item_2 = UI_TriggerItemType.chassisCover,
- timeLineStart = 48,
- timeLineEnd = 52
- });
- //4 螺丝刀拆网卡
- netWorkCardStepList.Add(new NetStepItemTriggerData()
- {
- questionType = Net_FaultQuestionType.trigger,
- faultType = Net_FaultType.netWorkCard,
- item_1 = UI_TriggerItemType.screwdriver,
- item_2 = UI_TriggerItemType.netWorkCard,
- timeLineStart = 52,
- timeLineEnd = 62
- });
- //5 插上新网卡
- netWorkCardStepList.Add(new NetStepItemTriggerData()
- {
- questionType = Net_FaultQuestionType.trigger,
- faultType = Net_FaultType.netWorkCard,
- item_1 = UI_TriggerItemType.netWorkCard,
- item_2 = UI_TriggerItemType.netWorkCardSetPos,
- timeLineStart = 84,
- timeLineEnd = 88
- });
- //6 拧紧螺丝
- netWorkCardStepList.Add(new NetStepItemTriggerData()
- {
- questionType = Net_FaultQuestionType.trigger,
- faultType = Net_FaultType.netWorkCard,
- item_1 = UI_TriggerItemType.screwdriver,
- item_2 = UI_TriggerItemType.netWorkCard,
- timeLineStart = 88,
- timeLineEnd = 96
- });
- //7 盖上盖子
- netWorkCardStepList.Add(new NetStepItemTriggerData()
- {
- questionType = Net_FaultQuestionType.trigger,
- faultType = Net_FaultType.netWorkCard,
- item_1 = UI_TriggerItemType.chassisCover,
- item_2 = UI_TriggerItemType.chassisCoverSetPos,
- timeLineStart = 97,
- timeLineEnd = 100
- });
- }
- private void InitLightModelStep()
- {
- lightModelStepList = new List<NetStepItemTriggerData>();
- //1 选择更换光模块
- lightModelStepList.Add(new NetStepItemTriggerData()
- {
- questionType = Net_FaultQuestionType.select,
- faultType = Net_FaultType.lightModel,
- item_1 = UI_TriggerItemType.none,
- item_2 = UI_TriggerItemType.none,
- timeLineStart = 19,
- timeLineEnd = -1
- });
- //2 合成手套
- lightModelStepList.Add(new NetStepItemTriggerData()
- {
- questionType = Net_FaultQuestionType.trigger,
- faultType = Net_FaultType.lightModel,
- item_1 = UI_TriggerItemType.hand,
- item_2 = UI_TriggerItemType.gloves,
- timeLineStart = 19,
- timeLineEnd = -1
- });
- //3 拔出光纤
- lightModelStepList.Add(new NetStepItemTriggerData()
- {
- questionType = Net_FaultQuestionType.trigger,
- faultType = Net_FaultType.lightModel,
- item_1 = UI_TriggerItemType.handWithGloves,
- item_2 = UI_TriggerItemType.opticalFiber,
- timeLineStart = 20,
- timeLineEnd = 24
- });
- //4 拔出光模块
- lightModelStepList.Add(new NetStepItemTriggerData()
- {
- questionType = Net_FaultQuestionType.trigger,
- faultType = Net_FaultType.lightModel,
- item_1 = UI_TriggerItemType.handWithGloves,
- item_2 = UI_TriggerItemType.lightModel,
- timeLineStart = 25,
- timeLineEnd = 29
- });
- //5 更换光模块
- lightModelStepList.Add(new NetStepItemTriggerData()
- {
- questionType = Net_FaultQuestionType.trigger,
- faultType = Net_FaultType.lightModel,
- item_1 = UI_TriggerItemType.lightModel,
- item_2 = UI_TriggerItemType.lightModelSetPos,
- timeLineStart = 38,
- timeLineEnd = 40
- });
- //6 插入光纤
- lightModelStepList.Add(new NetStepItemTriggerData()
- {
- questionType = Net_FaultQuestionType.trigger,
- faultType = Net_FaultType.lightModel,
- item_1 = UI_TriggerItemType.opticalFiber,
- item_2 = UI_TriggerItemType.lightModel,
- timeLineStart = 47,
- timeLineEnd = 50
- });
- }
- private void ReSetFaultFix()
- {
- currentStepIndex = 0;
- if (currentType == Net_FaultType.netWorkCard)
- {
- networkCardLine.Stop();
- networkCardLine.time = netWorkCardStepList[0].timeLineStart;
- }
- if (currentType == Net_FaultType.lightModel)
- {
- lightModelTimeLine.Stop();
- lightModelTimeLine.time = lightModelStepList[0].timeLineStart;
- }
- }
- private async void OnGetNet_FaultStart(object sender, GameEventArgs e)
- {
- Net_FaultStartEvent args = (Net_FaultStartEvent)e;
- if (args.type == Net_FaultType.netWorkCard && currentType != Net_FaultType.netWorkCard)
- {
- currentType = Net_FaultType.netWorkCard;
- currentStepIndex = 0;
- lightModelTimeLine.Stop();
- lightModelTimeLine.gameObject.SetActive(false);
- networkCardLine.gameObject.SetActive(true);
- networkCardLine.time = netWorkCardStepList[0].timeLineStart;
- networkCardLine.Play();
- await Task.Delay(50);
- networkCardLine.Pause();
- GameMain.Event.Fire(this, Net_FaultNextEvent.Create(currentType, currentStepIndex));
- }
- if (args.type == Net_FaultType.lightModel && currentType != Net_FaultType.lightModel)
- {
- currentType = Net_FaultType.lightModel;
- currentStepIndex = 0;
- networkCardLine.Stop();
- networkCardLine.gameObject.SetActive(false);
- lightModelTimeLine.gameObject.SetActive(true);
- lightModelTimeLine.time = lightModelStepList[0].timeLineStart;
- lightModelTimeLine.Play();
- await Task.Delay(50);
- lightModelTimeLine.Pause();
- GameMain.Event.Fire(this, Net_FaultNextEvent.Create(currentType, currentStepIndex));
- }
- }
- private async void OnGetUI_ItemMoveDone(object sender, GameEventArgs e)
- {
- List<NetStepItemTriggerData> currentList = null;
- int stepCount = -1;
- PlayableDirector currentPlayableDirector = null;
- switch (currentType)
- {
- case Net_FaultType.netWorkCard:
- currentList = netWorkCardStepList;
- stepCount = currentList.Count;
- currentPlayableDirector = networkCardLine;
- break;
- case Net_FaultType.lightModel:
- currentList = lightModelStepList;
- stepCount = currentList.Count;
- currentPlayableDirector = lightModelTimeLine;
- break;
- }
- if (currentList[currentStepIndex].questionType == Net_FaultQuestionType.trigger)
- {
- UI_ItemMoveDoneEvent args = (UI_ItemMoveDoneEvent)e;
- Debug.Log($"{args.item_1}:{args.item_2} {currentList[currentStepIndex].item_1}:{currentList[currentStepIndex].item_2}");
- bool pass = false;
- if (args.item_1 == currentList[currentStepIndex].item_1)
- {
- if (args.item_2 == currentList[currentStepIndex].item_2)
- {
- pass = true;
- }
- }
- else if (args.item_2 == currentList[currentStepIndex].item_1)
- {
- if (args.item_1 == currentList[currentStepIndex].item_2)
- {
- pass = true;
- }
- }
- if (pass)
- {
- if (currentList[currentStepIndex].timeLineEnd != -1)
- {
- currentPlayableDirector.Play();
- await Task.Delay((int)(currentList[currentStepIndex].timeLineEnd -
- currentList[currentStepIndex].timeLineStart) * 1000);
- currentPlayableDirector.Pause();
- }
- currentStepIndex++;
- if (currentStepIndex >= stepCount)
- {
- GameMain.Event.Fire(this, IT_TrainStudyDoneEvent.Create());
- }
- else
- {
- //todo nextStep
- currentPlayableDirector.time = currentList[currentStepIndex].timeLineStart;
- currentPlayableDirector.Play();
- await Task.Delay(50);
- currentPlayableDirector.Pause();
- //Debug.Log($"{currentType} {currentStepIndex}");
- GameMain.Event.Fire(this, Net_FaultNextEvent.Create(currentType, currentStepIndex));
- }
- }
- }
- }
-
- private async void OnGetSelectFaultItem(object sender, GameEventArgs e)
- {
- List<NetStepItemTriggerData> currentList = null;
- int stepCount = -1;
- PlayableDirector currentPlayableDirector=null;
- switch (currentType)
- {
- case Net_FaultType.netWorkCard:
- currentList = netWorkCardStepList;
- stepCount = currentList.Count;
- currentPlayableDirector = networkCardLine;
- break;
- case Net_FaultType.lightModel:
- currentList = lightModelStepList;
- stepCount = currentList.Count;
- currentPlayableDirector = lightModelTimeLine;
- break;
- }
-
- if (currentList[currentStepIndex].questionType == Net_FaultQuestionType.select)
- {
- Net_SelectFaultItemEvent args = (Net_SelectFaultItemEvent)e;
- if (args.faultType == currentList[currentStepIndex].faultType)
- {
- if (currentList[currentStepIndex].timeLineEnd != -1)
- {
- currentPlayableDirector.Play();
- await Task.Delay((int)(currentList[currentStepIndex].timeLineEnd-currentList[currentStepIndex].timeLineStart)*1000);
- currentPlayableDirector.Pause();
- }
- currentStepIndex++;
- if (currentStepIndex >= stepCount)
- {
- //todo 完成
- }
- else
- {
- //todo nextStep
- currentPlayableDirector.time = currentList[currentStepIndex].timeLineStart;
- currentPlayableDirector.Play();
- await Task.Delay(50);
- currentPlayableDirector.Pause();
- Debug.Log($"{currentType} {currentStepIndex}");
- GameMain.Event.Fire(this,Net_FaultNextEvent.Create(currentType,currentStepIndex));
- }
- }
- }
- }
- }
|