using System; using System.Collections; using System.Collections.Generic; using System.Threading.Tasks; using GameFramework.Event; using UnityEngine; using UnityEngine.Playables; //选项、拖拽 public enum IT_FaultQuestionType { select, trigger } public enum IT_FaultType { power, fan, ram, cpu, hardDisk, battery, none, } public struct StepItemTriggerData { public IT_FaultQuestionType questionType; public IT_FaultType faultType; //如果是选择题的话选择对应错误 public UI_TriggerItemType item_1; public UI_TriggerItemType item_2; public float timeLineStart; public float timeLineEnd; } public class IT_FaultFixCtrl : MonoBehaviour { public PlayableDirector powerTimeLine; public PlayableDirector fanTimeLine; public PlayableDirector ramTimeLine; public PlayableDirector hardDiskTimeLine; public PlayableDirector batteryTimeLine; //步骤统计 private int powerFaultStepCount = 6; private int fanFaultStepCount = 7; private int currentStepIndex = 0; private int ramFaultStepCount = 6; private int hardDiskStepCount = 6; private int batteryStepCount = 6; private IT_FaultType currentType = IT_FaultType.none; private List powerStepList; private List fanStepList; private List ramStepList; private List hardDiskStepList; private List batteryStepList; private void Awake() { InitPowerStep(); InitFanStep(); InitRamStep(); InitHardDiskStep(); InitBatteryStep(); } private void Start() { GameMain.Event.Subscribe(UI_ItemMoveDoneEvent.EventId, OnGetUI_ItemMoveDone); GameMain.Event.Subscribe(SelectFaultItemEvent.EventId, OnGetSelectFaultItem); GameMain.Event.Subscribe(IT_FaultStartEvent.EventId, OnGetIT_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(SelectFaultItemEvent.EventId, OnGetSelectFaultItem)) { GameMain.Event.Unsubscribe(SelectFaultItemEvent.EventId, OnGetSelectFaultItem); } if (GameMain.Event.Check(IT_FaultStartEvent.EventId, OnGetIT_FaultStart)) { GameMain.Event.Unsubscribe(IT_FaultStartEvent.EventId, OnGetIT_FaultStart); } } //初始化步骤中匹配的拖拽项 private void InitPowerStep() { powerStepList = new List(); //第1步选择电源问题 powerStepList.Add(new StepItemTriggerData() { questionType = IT_FaultQuestionType.select, faultType = IT_FaultType.power, item_1 = UI_TriggerItemType.none, item_2 = UI_TriggerItemType.none, timeLineStart = 25.1f, timeLineEnd = -1 }); //第2步拖拽手套到手上,合成戴手套的手 powerStepList.Add(new StepItemTriggerData() { questionType = IT_FaultQuestionType.trigger, faultType = IT_FaultType.power, item_1 = UI_TriggerItemType.hand, item_2 = UI_TriggerItemType.gloves, timeLineStart = -1, timeLineEnd = -1 }); //第3步拖拽戴手套的手到电源卡扣位置 powerStepList.Add(new StepItemTriggerData() { questionType = IT_FaultQuestionType.trigger, faultType = IT_FaultType.power, item_1 = UI_TriggerItemType.handWithGloves, item_2 = UI_TriggerItemType.powerLock, timeLineStart = 59, timeLineEnd = 61 }); //第4步拖拽戴手套的手到电源位置拉出电源 powerStepList.Add(new StepItemTriggerData() { questionType = IT_FaultQuestionType.trigger, faultType = IT_FaultType.power, item_1 = UI_TriggerItemType.handWithGloves, item_2 = UI_TriggerItemType.power, timeLineStart = 61, timeLineEnd = 65 }); //第5步拖拽电源到插槽位置 powerStepList.Add(new StepItemTriggerData() { questionType = IT_FaultQuestionType.trigger, faultType = IT_FaultType.power, item_1 = UI_TriggerItemType.power, item_2 = UI_TriggerItemType.powerSetPos, timeLineStart = 73, timeLineEnd = 79 }); //第6步拖拽戴手套的手到电源位置插紧电源 powerStepList.Add(new StepItemTriggerData() { questionType = IT_FaultQuestionType.trigger, faultType = IT_FaultType.power, item_1 = UI_TriggerItemType.handWithGloves, item_2 = UI_TriggerItemType.power, timeLineStart = 79, timeLineEnd = 84 }); } private void InitFanStep() { fanStepList = new List(); //第1步选择风扇问题 fanStepList.Add(new StepItemTriggerData() { questionType = IT_FaultQuestionType.select, faultType = IT_FaultType.fan, item_1 = UI_TriggerItemType.none, item_2 = UI_TriggerItemType.none, timeLineStart = 10, timeLineEnd = -1 }); //第2步拖拽手套到手上,合成戴手套的手 fanStepList.Add(new StepItemTriggerData() { questionType = IT_FaultQuestionType.trigger, faultType = IT_FaultType.fan, item_1 = UI_TriggerItemType.hand, item_2 = UI_TriggerItemType.gloves, timeLineStart = 61, timeLineEnd = -1 }); //第3步拖拽螺丝刀到机箱盖 fanStepList.Add(new StepItemTriggerData() { questionType = IT_FaultQuestionType.trigger, faultType = IT_FaultType.fan, item_1 = UI_TriggerItemType.screwdriver, item_2 = UI_TriggerItemType.chassisCoverLock, timeLineStart = 61, timeLineEnd = 66 }); //第4步拖拽戴手套的手到机箱盖卡口位置 fanStepList.Add(new StepItemTriggerData() { questionType = IT_FaultQuestionType.trigger, faultType = IT_FaultType.fan, item_1 = UI_TriggerItemType.handWithGloves, item_2 = UI_TriggerItemType.chassisCoverLock, timeLineStart = 67, timeLineEnd = 75 }); //第5步拖拽戴手套的手到风扇位置 fanStepList.Add(new StepItemTriggerData() { questionType = IT_FaultQuestionType.trigger, faultType = IT_FaultType.fan, item_1 = UI_TriggerItemType.handWithGloves, item_2 = UI_TriggerItemType.fan, timeLineStart = 75, timeLineEnd = 80 }); //第6步拖拽戴风扇到风扇安装位置 fanStepList.Add(new StepItemTriggerData() { questionType = IT_FaultQuestionType.trigger, faultType = IT_FaultType.fan, item_1 = UI_TriggerItemType.fan, item_2 = UI_TriggerItemType.fanSetPos, timeLineStart = 87, timeLineEnd = 90 }); //第7步拖拽戴机箱盖到安装位置 fanStepList.Add(new StepItemTriggerData() { questionType = IT_FaultQuestionType.trigger, faultType = IT_FaultType.fan, item_1 = UI_TriggerItemType.chassisCover, item_2 = UI_TriggerItemType.chassisCoverSetPos, timeLineStart = 93, timeLineEnd = 100 }); } private void InitRamStep() { ramStepList = new List(); //第1步选择内存问题 ramStepList.Add(new StepItemTriggerData() { questionType = IT_FaultQuestionType.select, faultType = IT_FaultType.ram, item_1 = UI_TriggerItemType.none, item_2 = UI_TriggerItemType.none, timeLineStart = 21, timeLineEnd = -1 }); //第2步拖拽手套到手上,合成戴手套的手 ramStepList.Add(new StepItemTriggerData() { questionType = IT_FaultQuestionType.trigger, faultType = IT_FaultType.ram, item_1 = UI_TriggerItemType.hand, item_2 = UI_TriggerItemType.gloves, timeLineStart = 21, timeLineEnd = -1 }); //第三步拆机箱盖 ramStepList.Add(new StepItemTriggerData() { questionType = IT_FaultQuestionType.trigger, faultType = IT_FaultType.ram, item_1 = UI_TriggerItemType.screwdriver, item_2 = UI_TriggerItemType.chassisCoverLock, timeLineStart = 21, timeLineEnd = 24 }); //第四步拆内存 ramStepList.Add(new StepItemTriggerData() { questionType = IT_FaultQuestionType.trigger, faultType = IT_FaultType.ram, item_1 = UI_TriggerItemType.handWithGloves, item_2 = UI_TriggerItemType.ram, timeLineStart = 44, timeLineEnd = 46 }); //第五步装内存 ramStepList.Add(new StepItemTriggerData() { questionType = IT_FaultQuestionType.trigger, faultType = IT_FaultType.ram, item_1 = UI_TriggerItemType.ram, item_2 = UI_TriggerItemType.ramPos, timeLineStart = 52, timeLineEnd = 62 }); //第六步装机箱盖 ramStepList.Add(new StepItemTriggerData() { questionType = IT_FaultQuestionType.trigger, faultType = IT_FaultType.ram, item_1 = UI_TriggerItemType.chassisCover, item_2 = UI_TriggerItemType.chassisCoverSetPos, timeLineStart = 68, timeLineEnd = 72 }); } private void InitHardDiskStep() { hardDiskStepList = new List(); //第一步选择硬盘问题 hardDiskStepList.Add(new StepItemTriggerData() { questionType = IT_FaultQuestionType.select, faultType = IT_FaultType.hardDisk, item_1 = UI_TriggerItemType.none, item_2 = UI_TriggerItemType.none, timeLineStart = 10, timeLineEnd = -1 }); //第二步合成戴手套的手 hardDiskStepList.Add(new StepItemTriggerData() { questionType = IT_FaultQuestionType.trigger, faultType = IT_FaultType.hardDisk, item_1 = UI_TriggerItemType.hand, item_2 = UI_TriggerItemType.gloves, timeLineStart = 10, timeLineEnd = -1 }); //第三步从机箱上拆下硬盘 hardDiskStepList.Add(new StepItemTriggerData() { questionType = IT_FaultQuestionType.trigger, faultType = IT_FaultType.hardDisk, item_1 = UI_TriggerItemType.handWithGloves, item_2 = UI_TriggerItemType.hardDisk, timeLineStart = 23, timeLineEnd = 33 }); //第四步用螺丝刀拆卸硬盘 hardDiskStepList.Add(new StepItemTriggerData() { questionType = IT_FaultQuestionType.trigger, faultType = IT_FaultType.hardDisk, item_1 = UI_TriggerItemType.screwdriver, item_2 = UI_TriggerItemType.hardDisk, timeLineStart = 40, timeLineEnd = 48 }); //第五步装上新硬盘 hardDiskStepList.Add(new StepItemTriggerData() { questionType = IT_FaultQuestionType.trigger, faultType = IT_FaultType.hardDisk, item_1 = UI_TriggerItemType.hardDisk, item_2 = UI_TriggerItemType.hardDiskPos, timeLineStart = 57, timeLineEnd = 63 }); //第六步插紧硬盘盒 hardDiskStepList.Add(new StepItemTriggerData() { questionType = IT_FaultQuestionType.trigger, faultType = IT_FaultType.hardDisk, item_1 = UI_TriggerItemType.handWithGloves, item_2 = UI_TriggerItemType.hardDiskPos, timeLineStart = 71, timeLineEnd = 74 }); } private void InitBatteryStep() { //第一步选择电池问题 batteryStepList = new List(); batteryStepList.Add(new StepItemTriggerData() { questionType = IT_FaultQuestionType.select, faultType = IT_FaultType.battery, item_1 = UI_TriggerItemType.none, item_2 = UI_TriggerItemType.none, timeLineStart = 10, timeLineEnd = -1 }); //第二部合成手套 batteryStepList.Add(new StepItemTriggerData() { questionType = IT_FaultQuestionType.trigger, faultType = IT_FaultType.battery, item_1 = UI_TriggerItemType.hand, item_2 = UI_TriggerItemType.gloves, timeLineStart = 21, timeLineEnd = -1 }); //第三步拔线 batteryStepList.Add(new StepItemTriggerData() { questionType = IT_FaultQuestionType.trigger, faultType = IT_FaultType.battery, item_1 = UI_TriggerItemType.handWithGloves, item_2 = UI_TriggerItemType.chassisCoverLock, timeLineStart = 21, timeLineEnd = 25 }); //第四步用螺丝刀拆电池 batteryStepList.Add(new StepItemTriggerData() { questionType = IT_FaultQuestionType.trigger, faultType = IT_FaultType.battery, item_1 = UI_TriggerItemType.screwdriver, item_2 = UI_TriggerItemType.battery, timeLineStart = 35, timeLineEnd = 43 }); //第五步装上新电池 batteryStepList.Add(new StepItemTriggerData() { questionType = IT_FaultQuestionType.trigger, faultType = IT_FaultType.battery, item_1 = UI_TriggerItemType.battery, item_2 = UI_TriggerItemType.batteryPos, timeLineStart = 45, timeLineEnd = 49 }); //第六步装上机箱盖 batteryStepList.Add(new StepItemTriggerData() { questionType = IT_FaultQuestionType.trigger, faultType = IT_FaultType.battery, item_1 = UI_TriggerItemType.chassisCover, item_2 = UI_TriggerItemType.chassisCoverSetPos, timeLineStart = 60, timeLineEnd = 63 }); } private void ReSetFaultFix() { currentStepIndex = 0; if (currentType == IT_FaultType.fan) { fanTimeLine.Stop(); fanTimeLine.time = fanStepList[0].timeLineStart; } if (currentType == IT_FaultType.power) { powerTimeLine.Stop(); powerTimeLine.time = powerStepList[0].timeLineStart; } if (currentType == IT_FaultType.ram) { ramTimeLine.Stop(); ramTimeLine.time = ramStepList[0].timeLineStart; } if (currentType == IT_FaultType.hardDisk) { hardDiskTimeLine.Stop(); hardDiskTimeLine.time = hardDiskStepList[0].timeLineStart; } if (currentType == IT_FaultType.battery) { batteryTimeLine.Stop(); batteryTimeLine.time = batteryStepList[0].timeLineStart; } } private async void OnGetIT_FaultStart(object sender, GameEventArgs e) { IT_FaultStartEvent args = (IT_FaultStartEvent)e; if (args.type == IT_FaultType.fan && currentType != IT_FaultType.fan) { currentType = IT_FaultType.fan; currentStepIndex = 0; powerTimeLine.Stop(); ramTimeLine.Stop(); hardDiskTimeLine.Stop(); batteryTimeLine.Stop(); powerTimeLine.gameObject.SetActive(false); ramTimeLine.gameObject.SetActive(false); hardDiskTimeLine.gameObject.SetActive(false); batteryTimeLine.gameObject.SetActive(false); fanTimeLine.gameObject.SetActive(true); fanTimeLine.time = fanStepList[0].timeLineStart; fanTimeLine.Play(); await Task.Delay(50); fanTimeLine.Pause(); GameMain.Event.Fire(this, IT_FaultNextEvent.Create(currentType, currentStepIndex)); } if (args.type == IT_FaultType.power && currentType != IT_FaultType.power) { currentType = IT_FaultType.power; currentStepIndex = 0; fanTimeLine.Stop(); ramTimeLine.Stop(); hardDiskTimeLine.Stop(); batteryTimeLine.Stop(); fanTimeLine.gameObject.SetActive(false); ramTimeLine.gameObject.SetActive(false); hardDiskTimeLine.gameObject.SetActive(false); batteryTimeLine.gameObject.SetActive(false); powerTimeLine.gameObject.SetActive(true); powerTimeLine.time = powerStepList[0].timeLineStart; powerTimeLine.Play(); await Task.Delay(50); powerTimeLine.Pause(); GameMain.Event.Fire(this, IT_FaultNextEvent.Create(currentType, currentStepIndex)); } if (args.type == IT_FaultType.ram && currentType != IT_FaultType.ram) { currentType = IT_FaultType.ram; currentStepIndex = 0; fanTimeLine.Stop(); powerTimeLine.Stop(); hardDiskTimeLine.Stop(); batteryTimeLine.Stop(); powerTimeLine.gameObject.SetActive(false); fanTimeLine.gameObject.SetActive(false); hardDiskTimeLine.gameObject.SetActive(false); batteryTimeLine.gameObject.SetActive(false); ramTimeLine.gameObject.SetActive(true); ramTimeLine.time = ramStepList[0].timeLineStart; ramTimeLine.Play(); await Task.Delay(50); ramTimeLine.Pause(); GameMain.Event.Fire(this, IT_FaultNextEvent.Create(currentType, currentStepIndex)); } if (args.type == IT_FaultType.hardDisk && currentType != IT_FaultType.hardDisk) { currentType = IT_FaultType.hardDisk; currentStepIndex = 0; fanTimeLine.Stop(); powerTimeLine.Stop(); ramTimeLine.Stop(); batteryTimeLine.Stop(); powerTimeLine.gameObject.SetActive(false); fanTimeLine.gameObject.SetActive(false); ramTimeLine.gameObject.SetActive(false); batteryTimeLine.gameObject.SetActive(false); hardDiskTimeLine.gameObject.SetActive(true); hardDiskTimeLine.time = hardDiskStepList[0].timeLineStart; hardDiskTimeLine.Play(); await Task.Delay(50); hardDiskTimeLine.Pause(); GameMain.Event.Fire(this, IT_FaultNextEvent.Create(currentType, currentStepIndex)); } if (args.type == IT_FaultType.battery && currentType != IT_FaultType.battery) { currentType = IT_FaultType.battery; currentStepIndex = 0; fanTimeLine.Stop(); powerTimeLine.Stop(); ramTimeLine.Stop(); hardDiskTimeLine.Stop(); powerTimeLine.gameObject.SetActive(false); fanTimeLine.gameObject.SetActive(false); ramTimeLine.gameObject.SetActive(false); hardDiskTimeLine.gameObject.SetActive(false); batteryTimeLine.gameObject.SetActive(true); batteryTimeLine.time = batteryStepList[0].timeLineStart; batteryTimeLine.Play(); await Task.Delay(50); batteryTimeLine.Pause(); GameMain.Event.Fire(this, IT_FaultNextEvent.Create(currentType, currentStepIndex)); } } private async void OnGetUI_ItemMoveDone(object sender, GameEventArgs e) { List currentList = null; int stepCount = -1; PlayableDirector currentPlayableDirector = null; switch (currentType) { case IT_FaultType.fan: currentList = fanStepList; stepCount = fanFaultStepCount; currentPlayableDirector = fanTimeLine; break; case IT_FaultType.power: currentList = powerStepList; stepCount = powerFaultStepCount; currentPlayableDirector = powerTimeLine; break; case IT_FaultType.ram: currentList = ramStepList; stepCount = ramFaultStepCount; currentPlayableDirector = ramTimeLine; break; case IT_FaultType.hardDisk: currentList = hardDiskStepList; stepCount = hardDiskStepCount; currentPlayableDirector = hardDiskTimeLine; break; case IT_FaultType.battery: currentList = batteryStepList; stepCount = batteryStepCount; currentPlayableDirector = batteryTimeLine; break; } if (currentList[currentStepIndex].questionType == IT_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, IT_FaultNextEvent.Create(currentType, currentStepIndex)); } } } } private async void OnGetSelectFaultItem(object sender, GameEventArgs e) { List currentList = null; int stepCount = -1; PlayableDirector currentPlayableDirector = null; switch (currentType) { case IT_FaultType.fan: currentList = fanStepList; stepCount = fanFaultStepCount; currentPlayableDirector = fanTimeLine; break; case IT_FaultType.power: currentList = powerStepList; stepCount = powerFaultStepCount; currentPlayableDirector = powerTimeLine; break; case IT_FaultType.ram: currentList = ramStepList; stepCount = ramFaultStepCount; currentPlayableDirector = ramTimeLine; break; case IT_FaultType.hardDisk: currentList = hardDiskStepList; stepCount = hardDiskStepCount; currentPlayableDirector = hardDiskTimeLine; break; case IT_FaultType.battery: currentList = batteryStepList; stepCount = batteryStepCount; currentPlayableDirector = batteryTimeLine; break; } if (currentList[currentStepIndex].questionType == IT_FaultQuestionType.select) { SelectFaultItemEvent args = (SelectFaultItemEvent)e; //Debug.Log($"{args.faultType} {currentList[currentStepIndex].faultType}"); 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, IT_FaultNextEvent.Create(currentType, currentStepIndex)); } } } } }