namespace ChivaXR { using UnityEngine; using Sirenix.OdinInspector; /// /// 步骤跳转状态(步骤跳转时依据当前ProcessElement物体查找接口组件并执行) /// public interface IProcessState { /// /// 步骤初始状态 /// /// true:进入当前状态--false:向前跳步 void EnterState(bool enterCurrent); /// /// 步骤结束状态 /// void ExitState(); void HalfQuit(); } /// /// 步骤组件 /// public class ProcessElement : MonoBehaviour { /// /// 当前步骤StepID /// public int stepID; /// /// 当前步骤是否激活 /// public bool active; /// /// 当前步骤完成情况 /// public bool finished; /// /// 操作前预处理逻辑 /// [HideInInspector] public PreprocessBase preprocess; /// /// 操作类基类 /// public ProcessBase processBase; public System.Action processElementEnterHandler; public System.Action processElementExitHandle; /// /// 流程使用状态 /// /// public void SetProcessActive(bool state) { active = state; } /// /// 进入当前步骤 /// public void Enter() { SetProcessActive(true); SetEnterState(true); Debug.Log("进入" + stepID + "步骤"); EnterProProcess(); } public void EnterProProcess() { if (preprocess == null) { ProProcessFinished(); } else { preprocess.Enter(this); } } /// /// 预处理结束进度操作流程 /// public void ProProcessFinished() { ProcessManagement.Instance.preprocessFnishedEvent?.Invoke(this); if (processBase == null) { Debug.LogError("缺少" + stepID + "步 ProcedureBase----" + this.name); Exit(); return; } processBase.Enter(this); processElementEnterHandler?.Invoke(this); } /// /// 离开当前步骤 /// public void Exit() { SetProcessActive(false); SetExitState(); finished = true; processElementExitHandle?.Invoke(this); ProcessManagement.Instance.EnterNextProcess(); } /// /// 操作过程中,中途退出(受跳步影响) /// /// 向前跳步退出 public void QuitHalfWay() { AnimationDriver.StopAllAnimation(); SetProcessActive(false); if (processBase != null) { processBase.QuitHalfWay(); } if(preprocess!=null) { preprocess.QuitHalfWay(); } foreach (var item in this.GetComponents()) { item.HalfQuit(); } } /// /// 设置进入时状态 /// /// 向前跳步状态 public void SetEnterState(bool currentEnter = true) { if (processBase != null) { processBase.SetEnterState(); } foreach (var item in this.GetComponents()) { item.EnterState(currentEnter); } } /// /// 设置离开时状态 /// public void SetExitState() { if (processBase != null) { processBase.SetExitState(); } foreach (var item in this.GetComponents()) { item.ExitState(); } } [HideIf("processBase")] [Button("创建PB_OpData")] public ProcessBase InitOpData() { if (processBase == null) { processBase = this.gameObject.GetComponent() == null ? this.gameObject.AddComponent() : this.gameObject.GetComponent(); } return processBase; } #region 参数设置 /// /// 名字 /// public void SetName() { if (processBase != null) { this.gameObject.name = "第" + stepID + "步:" + processBase.GetPBDescribe(); return; } this.gameObject.name = "第" + stepID + "步"; } public void SetName(string name) { this.gameObject.name = "第" + stepID + "步:" + name; } #endregion } }