123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Threading.Tasks;
- using GameFramework.Event;
- using UnityEngine;
- using UnityEngine.Playables;
- using UnityEngine.Serialization;
- public enum Cool_FaultQuestionType
- {
- select,
- trigger
- }
- public enum Cool_FaultType
- {
- highPressure,
- lowPressure,
- airConditioning,
- pumpError,
- none,
- }
- public struct CoolStepItemTriggerData
- {
- public Cool_FaultQuestionType questionType;
- public Cool_FaultType faultType; //如果是选择题的话选择对应错误
- public UI_TriggerItemType item_1;
- public UI_TriggerItemType item_2;
- public float timeLineStart;
- public float timeLineEnd;
- }
- public class Cool_FaultFixCtrl : MonoBehaviour
- {
- public PlayableDirector highPressureTimeLine;
- public PlayableDirector lowPressureTimeLine;
- public PlayableDirector fault3TimeLine;
- //步骤统计
- private int currentStepIndex = 0;
- private Cool_FaultType currentType = Cool_FaultType.none;
- private List<CoolStepItemTriggerData> highPressureStepList;
- private List<CoolStepItemTriggerData> lowPressureStepList;
- private List<CoolStepItemTriggerData> fault3StepList;
- private void Awake()
- {
- InitHighPressureStep();
- InitLowPressureStep();
- InitFault3Step();
- }
- private void Start()
- {
- GameMain.Event.Subscribe(UI_ItemMoveDoneEvent.EventId, OnGetUI_ItemMoveDone);
- GameMain.Event.Subscribe(Cool_SelectFaultItemEvent.EventId, OnGetSelectFaultItem);
- GameMain.Event.Subscribe(Cool_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(Cool_SelectFaultItemEvent.EventId, OnGetSelectFaultItem))
- {
- GameMain.Event.Unsubscribe(Cool_SelectFaultItemEvent.EventId, OnGetSelectFaultItem);
- }
- if (GameMain.Event.Check(Cool_FaultStartEvent.EventId, OnGetNet_FaultStart))
- {
- GameMain.Event.Unsubscribe(Cool_FaultStartEvent.EventId, OnGetNet_FaultStart);
- }
- }
-
- private void InitHighPressureStep()
- {
- highPressureStepList = new List<CoolStepItemTriggerData>();
- //1 选择高压
- highPressureStepList.Add(new CoolStepItemTriggerData()
- {
- questionType = Cool_FaultQuestionType.select,
- faultType = Cool_FaultType.highPressure,
- item_1 = UI_TriggerItemType.none,
- item_2 = UI_TriggerItemType.none,
- timeLineStart = 11,
- timeLineEnd = -1
- });
- //2 关闭阀门
- highPressureStepList.Add(new CoolStepItemTriggerData()
- {
- questionType = Cool_FaultQuestionType.trigger,
- faultType = Cool_FaultType.highPressure,
- item_1 = UI_TriggerItemType.hand,
- item_2 = UI_TriggerItemType.valve,
- timeLineStart = 24,
- timeLineEnd = 26
- });
- //3 打开盖子
- highPressureStepList.Add(new CoolStepItemTriggerData()
- {
- questionType = Cool_FaultQuestionType.trigger,
- faultType = Cool_FaultType.highPressure,
- item_1 = UI_TriggerItemType.hand,
- item_2 = UI_TriggerItemType.coolCover,
- timeLineStart = 30,
- timeLineEnd = 32
- });
- //4 清理管道
- highPressureStepList.Add(new CoolStepItemTriggerData()
- {
- questionType = Cool_FaultQuestionType.trigger,
- faultType = Cool_FaultType.highPressure,
- item_1 = UI_TriggerItemType.cleaningRod,
- item_2 = UI_TriggerItemType.coolCover,
- timeLineStart = 34,
- timeLineEnd = 45
- });
- }
- private void InitLowPressureStep()
- {
- lowPressureStepList = new List<CoolStepItemTriggerData>();
- //1 选择低压
- lowPressureStepList.Add(new CoolStepItemTriggerData()
- {
- questionType = Cool_FaultQuestionType.select,
- faultType = Cool_FaultType.lowPressure,
- item_1 = UI_TriggerItemType.none,
- item_2 = UI_TriggerItemType.none,
- timeLineStart = 13,
- timeLineEnd = -1
- });
-
- //2 连接冷媒管道
- lowPressureStepList.Add(new CoolStepItemTriggerData()
- {
- questionType = Cool_FaultQuestionType.trigger,
- faultType = Cool_FaultType.lowPressure,
- item_1 = UI_TriggerItemType.refrigerant,
- item_2 = UI_TriggerItemType.refrigerantPos,
- timeLineStart = 24,
- timeLineEnd = 30
- });
-
- //3 打开冷媒阀门
- lowPressureStepList.Add(new CoolStepItemTriggerData()
- {
- questionType = Cool_FaultQuestionType.trigger,
- faultType = Cool_FaultType.lowPressure,
- item_1 = UI_TriggerItemType.hand,
- item_2 = UI_TriggerItemType.refrigerant,
- timeLineStart = 30,
- timeLineEnd = 38
- });
- //4 关闭阀门
- lowPressureStepList.Add(new CoolStepItemTriggerData()
- {
- questionType = Cool_FaultQuestionType.trigger,
- faultType = Cool_FaultType.lowPressure,
- item_1 = UI_TriggerItemType.hand,
- item_2 = UI_TriggerItemType.valve,
- timeLineStart = 40,
- timeLineEnd = 43
- });
- }
- private void InitFault3Step()
- {
- fault3StepList = new List<CoolStepItemTriggerData>();
- //选择安全阀问题
- fault3StepList.Add(new CoolStepItemTriggerData()
- {
- questionType = Cool_FaultQuestionType.select,
- faultType = Cool_FaultType.pumpError,
- item_1 = UI_TriggerItemType.none,
- item_2 = UI_TriggerItemType.none,
- timeLineStart = 3,
- timeLineEnd = -1
- });
- //拧下阀门螺丝
- fault3StepList.Add(new CoolStepItemTriggerData()
- {
- questionType = Cool_FaultQuestionType.trigger,
- faultType = Cool_FaultType.pumpError,
- item_1 = UI_TriggerItemType.hand,
- item_2 = UI_TriggerItemType.screw,
- timeLineStart = 14,
- timeLineEnd = 17
- });
- //拆开阀座
- fault3StepList.Add(new CoolStepItemTriggerData()
- {
- questionType = Cool_FaultQuestionType.trigger,
- faultType = Cool_FaultType.pumpError,
- item_1 = UI_TriggerItemType.hand,
- item_2 = UI_TriggerItemType.valve,
- timeLineStart = 19,
- timeLineEnd = 26
- });
- //清理阀圈
- fault3StepList.Add(new CoolStepItemTriggerData()
- {
- questionType = Cool_FaultQuestionType.trigger,
- faultType = Cool_FaultType.pumpError,
- item_1 = UI_TriggerItemType.cleaningRod,
- item_2 = UI_TriggerItemType.valve,
- timeLineStart = 28,
- timeLineEnd = 35
- });
- //装好阀座
- fault3StepList.Add(new CoolStepItemTriggerData()
- {
- questionType = Cool_FaultQuestionType.trigger,
- faultType = Cool_FaultType.pumpError,
- item_1 = UI_TriggerItemType.hand,
- item_2 = UI_TriggerItemType.valve,
- timeLineStart = 38,
- timeLineEnd = 42
- });
- //装上螺丝
- fault3StepList.Add(new CoolStepItemTriggerData()
- {
- questionType = Cool_FaultQuestionType.trigger,
- faultType = Cool_FaultType.pumpError,
- item_1 = UI_TriggerItemType.screw,
- item_2 = UI_TriggerItemType.valve,
- timeLineStart = 47,
- timeLineEnd = 49
- });
- }
- private void ReSetFaultFix()
- {
- currentStepIndex = 0;
- if (currentType == Cool_FaultType.highPressure)
- {
- highPressureTimeLine.Stop();
- highPressureTimeLine.time = highPressureStepList[0].timeLineStart;
- }
- if (currentType == Cool_FaultType.lowPressure)
- {
- lowPressureTimeLine.Stop();
- lowPressureTimeLine.time = lowPressureStepList[0].timeLineStart;
- }
-
- if (currentType == Cool_FaultType.pumpError)
- {
- fault3TimeLine.Stop();
- fault3TimeLine.time = fault3StepList[0].timeLineStart;
- }
- }
- private async void OnGetNet_FaultStart(object sender, GameEventArgs e)
- {
- Cool_FaultStartEvent args = (Cool_FaultStartEvent)e;
- if (args.type == Cool_FaultType.highPressure && currentType != Cool_FaultType.highPressure)
- {
- currentType = Cool_FaultType.highPressure;
- currentStepIndex = 0;
- lowPressureTimeLine.Stop();
- lowPressureTimeLine.gameObject.SetActive(false);
-
- fault3TimeLine.Stop();
- fault3TimeLine.gameObject.SetActive(false);
-
- highPressureTimeLine.gameObject.SetActive(true);
- highPressureTimeLine.time = highPressureStepList[0].timeLineStart;
- highPressureTimeLine.Play();
- await Task.Delay(50);
- highPressureTimeLine.Pause();
- GameMain.Event.Fire(this, Cool_FaultNextEvent.Create(currentType, currentStepIndex));
- }
- if (args.type == Cool_FaultType.lowPressure && currentType != Cool_FaultType.lowPressure)
- {
- currentType = Cool_FaultType.lowPressure;
- currentStepIndex = 0;
- highPressureTimeLine.Stop();
- highPressureTimeLine.gameObject.SetActive(false);
-
- fault3TimeLine.Stop();
- fault3TimeLine.gameObject.SetActive(false);
-
-
- lowPressureTimeLine.gameObject.SetActive(true);
- lowPressureTimeLine.time = lowPressureStepList[0].timeLineStart;
- lowPressureTimeLine.Play();
- await Task.Delay(50);
- lowPressureTimeLine.Pause();
- GameMain.Event.Fire(this, Cool_FaultNextEvent.Create(currentType, currentStepIndex));
- }
-
-
- if (args.type == Cool_FaultType.pumpError && currentType != Cool_FaultType.pumpError)
- {
- currentType = Cool_FaultType.pumpError;
- currentStepIndex = 0;
- highPressureTimeLine.Stop();
-
- highPressureTimeLine.gameObject.SetActive(false);
-
- lowPressureTimeLine.Stop();
- lowPressureTimeLine.gameObject.SetActive(false);
-
-
- fault3TimeLine.gameObject.SetActive(true);
- fault3TimeLine.time = fault3StepList[0].timeLineStart;
- fault3TimeLine.Play();
- await Task.Delay(50);
- fault3TimeLine.Pause();
- GameMain.Event.Fire(this, Cool_FaultNextEvent.Create(currentType, currentStepIndex));
- }
- }
- private async void OnGetUI_ItemMoveDone(object sender, GameEventArgs e)
- {
- List<CoolStepItemTriggerData> currentList = null;
- int stepCount = -1;
- PlayableDirector currentPlayableDirector = null;
- switch (currentType)
- {
- case Cool_FaultType.highPressure:
- currentList = highPressureStepList;
- stepCount = currentList.Count;
- currentPlayableDirector = highPressureTimeLine;
- break;
- case Cool_FaultType.lowPressure:
- currentList = lowPressureStepList;
- stepCount = currentList.Count;
- currentPlayableDirector = lowPressureTimeLine;
- break;
-
- case Cool_FaultType.pumpError:
- currentList = fault3StepList;
- stepCount = currentList.Count;
- currentPlayableDirector = fault3TimeLine;
- break;
- }
- if (currentList[currentStepIndex].questionType == Cool_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, Cool_FaultNextEvent.Create(currentType, currentStepIndex));
- }
- }
- }
- }
-
- private async void OnGetSelectFaultItem(object sender, GameEventArgs e)
- {
- List<CoolStepItemTriggerData> currentList = null;
- int stepCount = -1;
- PlayableDirector currentPlayableDirector=null;
- switch (currentType)
- {
- case Cool_FaultType.highPressure:
- currentList = highPressureStepList;
- stepCount = currentList.Count;
- currentPlayableDirector = highPressureTimeLine;
- break;
- case Cool_FaultType.lowPressure:
- currentList = lowPressureStepList;
- stepCount = currentList.Count;
- currentPlayableDirector = lowPressureTimeLine;
- break;
- case Cool_FaultType.pumpError:
- currentList = fault3StepList;
- stepCount = currentList.Count;
- currentPlayableDirector = fault3TimeLine;
- break;
- }
-
- if (currentList[currentStepIndex].questionType == Cool_FaultQuestionType.select)
- {
- Cool_SelectFaultItemEvent args = (Cool_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 完成
- 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,Cool_FaultNextEvent.Create(currentType,currentStepIndex));
- }
- }
- }
- }
- }
|