369 lines
13 KiB
C#
369 lines
13 KiB
C#
using CG.UTility;
|
|
using DG.Tweening;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Linq;
|
|
using UnityEngine;
|
|
using ZXK.GYJQR;
|
|
using Component = UnityEngine.Component;
|
|
/// <summary>
|
|
/// 执行步骤枚举
|
|
/// </summary>
|
|
namespace ZXK.GYJQR
|
|
{
|
|
public enum ExcuteState
|
|
{
|
|
Excute,//执行当前步骤
|
|
Switch,//切换下一个步骤
|
|
None
|
|
}
|
|
/// <summary>
|
|
/// 步骤管理类
|
|
/// </summary>
|
|
public class StepManager : Singleton<StepManager>
|
|
{
|
|
public string CurAZBSState = "";//当前大步骤类型枚举
|
|
[HideInInspector]
|
|
private Dictionary<string, List<Step_0>> stepBigSmallDic = new Dictionary<string, List<Step_0>>();
|
|
private List<string> azbsBigStepArray = new List<string>();//保存大步骤数据报文的字典
|
|
[HideInInspector]
|
|
public Step_0 CurStep;//当前执行的小步骤
|
|
private Dictionary<string, Step_0> dictStep;//保存小步骤类的字典
|
|
private string saveStepPath = null;//保存步骤类的路径
|
|
[HideInInspector]
|
|
public AZBS nextAZBS;//下一个大步骤
|
|
[HideInInspector]
|
|
public float totalScore;//总分值
|
|
private void Start()
|
|
{
|
|
dictStep = new Dictionary<string, Step_0>();
|
|
saveStepPath = "Prefabs/Step";
|
|
}
|
|
public void Update()
|
|
{
|
|
CurStep?.StepUpdate();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 执行到步骤的操作
|
|
/// </summary>
|
|
public void OnExcuteAZBS(ExcuteState excuteState)
|
|
{
|
|
DOTween.PauseAll();
|
|
switch (excuteState)
|
|
{
|
|
case ExcuteState.Excute:
|
|
CurAZBSState = GameManager.Instance._DataAZBSHandler.CurAZBShandler.Value.stepName;
|
|
break;
|
|
case ExcuteState.Switch:
|
|
CurAZBSState = nextAZBS.stepName;
|
|
GameManager.Instance._DataAZBSHandler.CurAZBShandler.Value = nextAZBS;
|
|
break;
|
|
case ExcuteState.None:
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
OnSwitchAZBS(CurAZBSState);
|
|
}
|
|
/// <summary>
|
|
/// 切换大步骤函数
|
|
/// </summary>
|
|
/// <param name="zBS"></param>
|
|
private void OnSwitchAZBS(string state)
|
|
{
|
|
CreateStep();
|
|
//Add By CG 每次切换步骤的时候需要判定当前示教器状态,因为轴向校零的时候示教器状态变动较大
|
|
//ModelManager.Instance.InitAllGeo();
|
|
ModelManager.Instance.InitZXXLSJQState(false);
|
|
switch (state)
|
|
{
|
|
case ConstCtrl.BigStepName_LJQDDL:
|
|
SwitchStep("LJQDDL_Step_1");
|
|
break;
|
|
case ConstCtrl.BigStepName_LJXHDL:
|
|
SwitchStep("LJXHDL_Step_1");
|
|
break;
|
|
case ConstCtrl.BigStepName_SJQJX:
|
|
SwitchStep("SJQJX_Step_1");
|
|
break;
|
|
case ConstCtrl.BigStepName_LJDYX:
|
|
SwitchStep("LJDYX_Step_1");
|
|
break;
|
|
case ConstCtrl.BigStepName_SBKJ:
|
|
SwitchStep("SBKJ_Step_1");
|
|
break;
|
|
case ConstCtrl.BigStepName_ZXXL:
|
|
ModelManager.Instance.InitZXXLSJQState(true);
|
|
SwitchStep("ZXXL_Step_1");
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 创建步骤类到界面中
|
|
/// </summary>
|
|
private void CreateStep()
|
|
{
|
|
stepBigSmallDic.Clear();
|
|
dictStep.Clear();
|
|
OnReset();
|
|
InitData();
|
|
InitStep(stepBigSmallDic[CurAZBSState]);
|
|
}
|
|
/// <summary>
|
|
/// 每一次切换大步骤时对步骤进行重置
|
|
/// </summary>
|
|
public void OnReset()
|
|
{
|
|
CameraControl control = Camera.main.GetComponent<CameraControl>();
|
|
control.transform.DOKill();
|
|
ModelManager.Instance.OnEndCallBack();
|
|
//切换大步骤时关闭所有的菜单
|
|
AdjustAngleMenu[] angleMenus = FindObjectsOfType<AdjustAngleMenu>();
|
|
foreach (var item in angleMenus)
|
|
{
|
|
item.gameObject.SetActive(false);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 初始话结构体列表
|
|
/// </summary>
|
|
private void InitData()
|
|
{
|
|
AZBS curStep = GameManager.Instance._DataAZBSHandler.CurAZBShandler.Value;
|
|
CurAZBSState = curStep.stepName;
|
|
stepBigSmallDic= GetAZBSDic();
|
|
GetNextAZBS(CurAZBSState);
|
|
}
|
|
/// <summary>
|
|
/// 通过遍历AZBS列表获取到对应的步骤类列表
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
private Dictionary<string, List<Step_0>> GetAZBSDic()
|
|
{
|
|
Dictionary<string, List<Step_0>> dicAZBSStateStep = new Dictionary<string, List<Step_0>>();
|
|
List<AZBS> aZBs = GameManager.Instance._DataAZBSHandler.AZBSDataArray;
|
|
for (int i = 0; i < aZBs.Count; i++)
|
|
{
|
|
string aZBSState = aZBs[i].stepName;
|
|
if (aZBSState.Equals("OVER")) continue;
|
|
string _stepCtrl = aZBs[i].ctrlScriptName;
|
|
|
|
Type type = Type.GetType("ZXK.GYJQR."+_stepCtrl);
|
|
Step_0 instance = Activator.CreateInstance(type, aZBs[i]) as Step_0;
|
|
if (dicAZBSStateStep.ContainsKey(aZBSState))
|
|
{
|
|
dicAZBSStateStep[aZBSState].Add(instance);
|
|
}
|
|
else
|
|
{
|
|
List<Step_0> aZBSSteps = new List<Step_0>();
|
|
aZBSSteps.Add(instance);
|
|
dicAZBSStateStep.Add(aZBSState, aZBSSteps);
|
|
}
|
|
if (!azbsBigStepArray.Contains(aZBSState))
|
|
{
|
|
azbsBigStepArray.Add(aZBSState);
|
|
}
|
|
}
|
|
return dicAZBSStateStep;
|
|
}
|
|
/// <summary>
|
|
/// 大步骤完成后切换到下一个
|
|
/// </summary>
|
|
private void GetNextAZBS(string context)
|
|
{
|
|
string newContext = GetAZBSState(context);
|
|
foreach (AZBS item in GameManager.Instance._DataAZBSHandler.AZBSDataArray)
|
|
{
|
|
string nextState = item.stepName;
|
|
if (nextState.Equals(newContext))
|
|
{
|
|
nextAZBS = item;
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 根据小步骤的名字切换当前的步骤
|
|
/// </summary>
|
|
public void SwitchStep(string stepName)
|
|
{
|
|
Step_0 nextStep = GetStep(stepName);
|
|
if (nextStep == null)
|
|
{
|
|
WDebug.LogError("当前字典中没有寻找到" + nextStep.GetType().Name + "的步骤子类");
|
|
}
|
|
if (nextStep != null)
|
|
{
|
|
CurStep = nextStep;
|
|
if (GameManager.Instance._EnteredTrainSceneArray.Contains(GameManager.Instance._CurSystemType))
|
|
{
|
|
CurStep?.StepStart();
|
|
PopUpMng.PopAddAudToast(CurStep._ItemAttr.tipText, CurStep._ItemAttr.sound, 0.0f);
|
|
}
|
|
else
|
|
{
|
|
StartCoroutine("EnteredPlayAud");
|
|
}
|
|
}
|
|
}
|
|
private System.Collections.IEnumerator EnteredPlayAud()
|
|
{
|
|
yield return new WaitForSeconds(0.5f);
|
|
FirstEnterTrainPanel firstGeo = CG.Framework.UI_Manage.Instance.GetPanel("FirstEnterTrainPanel").GetComponent<FirstEnterTrainPanel>();
|
|
firstGeo.EnteredEvent += () =>
|
|
{
|
|
CurStep?.StepStart();
|
|
PopUpMng.PopAddAudToast(CurStep._ItemAttr.tipText, CurStep._ItemAttr.sound, 0.0f);
|
|
};
|
|
}
|
|
/// <summary>
|
|
/// 根据名称获取到对应的步骤
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
private Step_0 GetStep(string stepName)
|
|
{
|
|
if (!dictStep.ContainsKey(stepName))
|
|
{
|
|
WDebug.LogError("当前字典中没有寻找到" + stepName + "的步骤子类");
|
|
}
|
|
Step_0 step = null;
|
|
dictStep.TryGetValue(stepName, out step);
|
|
return step;
|
|
}
|
|
/// <summary>
|
|
/// 根据唯一标识符获取当前步骤
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public Step_0 GetIdentityStep(string stepIdentity)
|
|
{
|
|
foreach (var item in dictStep)
|
|
{
|
|
Step_0 step = item.Value;
|
|
if (step._ItemAttr.id.ToString().Equals(stepIdentity))
|
|
{
|
|
return step;
|
|
}
|
|
}
|
|
WDebug.LogError("当前字典中没有寻找到" + stepIdentity + "的步骤子类");
|
|
return null;
|
|
}
|
|
/// <summary>
|
|
/// 根据唯一标识符切换下一个步骤
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public void SwitchIdentityStep(Step_0 step)
|
|
{
|
|
for (int i = 0; i < dictStep.Count; i++)
|
|
{
|
|
var key = dictStep.ElementAt(i);
|
|
if (key.Value._ItemAttr.id.Equals(step._ItemAttr.id))
|
|
{
|
|
var newValue = dictStep.ElementAt(i + 1).Value;
|
|
WDebug.Log("下一个小步骤的名称为" + newValue.GetType().Name);
|
|
SwitchStep(newValue.GetType().Name);
|
|
}
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 初始化字典
|
|
/// </summary>
|
|
private void InitStep(List<Step_0> aZBSSteps)
|
|
{
|
|
if (aZBSSteps.Count == 0)
|
|
{
|
|
WDebug.LogError("当前界面没有实例化的步骤子类");
|
|
}
|
|
foreach (var item in aZBSSteps)
|
|
{
|
|
if (!dictStep.ContainsKey(item.GetType().Name))
|
|
{
|
|
dictStep.Add(item.GetType().Name, item);
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 根据字符串获得到当前大步骤枚举下一个的元素值
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
private string GetAZBSState(string context)
|
|
{
|
|
for (int i = 0; i < azbsBigStepArray.Count; i++)
|
|
{
|
|
var key = azbsBigStepArray.ElementAt(i);
|
|
if (key.Equals(context))
|
|
{
|
|
if ((i + 1) == azbsBigStepArray.Count)
|
|
{
|
|
var newKey = azbsBigStepArray.ElementAt(i);
|
|
return newKey;
|
|
}
|
|
else
|
|
{
|
|
var newKey = azbsBigStepArray.ElementAt(i + 1);
|
|
return newKey;
|
|
}
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public void OnSwitchInit(AZBS curState, AZBS nextState)
|
|
{
|
|
for (int i = 0; i < ModelManager.Instance.modelDatas.Count; i++)
|
|
{
|
|
GameObject itemGeo = ModelManager.Instance.modelDatas[i].modelPart;
|
|
OutLineRender lineR;
|
|
if (itemGeo.TryGetComponent<OutLineRender>(out lineR))
|
|
{
|
|
lineR.enabled = false;
|
|
}
|
|
}
|
|
|
|
if (curState.id > nextState.id)
|
|
{
|
|
ModelManager.Instance.InitAllGeo();
|
|
}
|
|
switch (nextState.stepName)
|
|
{
|
|
case ConstCtrl.BigStepName_LJQDDL:
|
|
ModelManager.Instance.InitAllGeo();
|
|
break;
|
|
case ConstCtrl.BigStepName_LJXHDL:
|
|
ModelManager.Instance.InitLJQDDLState(true);
|
|
break;
|
|
case ConstCtrl.BigStepName_SJQJX:
|
|
ModelManager.Instance.InitLJQDDLState(true);
|
|
ModelManager.Instance.InitLJXHDLState(true);
|
|
break;
|
|
case ConstCtrl.BigStepName_LJDYX:
|
|
ModelManager.Instance.InitLJQDDLState(true);
|
|
ModelManager.Instance.InitLJXHDLState(true);
|
|
ModelManager.Instance.InitSJQDLState(true);
|
|
ModelManager.Instance.InitLJDYXState(false);
|
|
break;
|
|
case ConstCtrl.BigStepName_SBKJ:
|
|
ModelManager.Instance.InitLJQDDLState(true);
|
|
ModelManager.Instance.InitLJXHDLState(true);
|
|
ModelManager.Instance.InitSJQDLState(true);
|
|
ModelManager.Instance.InitLJDYXState(true);
|
|
ModelManager.Instance.InitSBKJState(false);
|
|
break;
|
|
case ConstCtrl.BigStepName_ZXXL:
|
|
ModelManager.Instance.InitLJQDDLState(true);
|
|
ModelManager.Instance.InitLJXHDLState(true);
|
|
ModelManager.Instance.InitSJQDLState(true);
|
|
ModelManager.Instance.InitLJDYXState(true);
|
|
ModelManager.Instance.InitSBKJState(true);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|