/// <summary> /// 恢复到指定步骤 /// </summary> /// <param name="stepID">步骤ID</param> /// <returns>恢复成功/失败</returns> public bool RestoreStep(string stepID) { if (_running && !_executing) { if (!_stepContentIndexs.ContainsKey(stepID)) { return(false); } int index = _stepContentIndexs[stepID]; if (index < 0 || index >= _currentStep) { return(false); } while (_currentStep >= index) { _currentContent = _stepContents[_currentStep]; _currentTarget = _currentContent.Target.GetComponent <StepTarget>(); RestoreStepEvent?.Invoke(_currentContent, _stepContentEnables.ContainsKey(_currentContent.GUID) ? _stepContentEnables[_currentContent.GUID] : false); //创建步骤助手 if (_currentHelper == null && _currentContent.Helper != "<None>") { Type type = GlobalTools.GetTypeInRunTimeAssemblies(_currentContent.Helper); if (type != null) { _currentHelper = Activator.CreateInstance(type) as StepHelper; _currentHelper.Target = _currentTarget; _currentHelper.Task = StepHelperTask.Restore; _currentHelper.OnInit(); } else { GlobalTools.LogError(string.Format("【步骤:{0}】的助手 {1} 丢失!", _currentStep + 1, _currentContent.Helper)); } } //助手执行恢复 if (_currentHelper != null) { _currentHelper.Task = StepHelperTask.Restore; _currentHelper.OnRestore(); _currentHelper.OnTermination(); _currentHelper = null; } _currentStep -= 1; } _currentStep = index; BeginCurrentStep(); return(true); } else { return(false); } }
/// <summary> /// 恢复到指定步骤 /// </summary> public bool RestoreStep(int stepIndex) { if (_ongoing && !_running) { if (stepIndex < 0 || stepIndex >= _currentStep) { return(false); } while (_currentStep >= stepIndex) { _currentContent = _stepContents[_currentStep]; _currentTarget = _currentContent.Target.GetComponent <StepTarget>(); if (RestoreStepEvent != null) { RestoreStepEvent(_currentContent); } //创建步骤助手 if (_currentHelper == null && _currentContent.Helper != "<None>") { Type type = GlobalTools.GetTypeInRunTimeAssemblies(_currentContent.Helper); if (type != null) { _currentHelper = Activator.CreateInstance(type) as StepHelper; _currentHelper.Target = _currentTarget; _currentHelper.Task = StepHelperTask.Restore; _currentHelper.OnInit(); } else { GlobalTools.LogError("【步骤:" + (_currentStep + 1) + "】的助手 " + _currentContent.Helper + " 丢失!"); } } //助手执行恢复 if (_currentHelper != null) { _currentHelper.Task = StepHelperTask.Restore; _currentHelper.OnRestore(); _currentHelper.OnTermination(); _currentHelper = null; } _currentStep -= 1; } _currentStep = stepIndex; BeginCurrentStep(); return(true); } else { return(false); } }
/// <summary> /// 结束步骤流程 /// </summary> public void End() { if (_currentHelper != null) { _currentHelper.OnTermination(); _currentHelper = null; } _currentStepIndex = 0; _currentContent = null; _currentTarget = null; _running = false; _pause = false; _executing = false; StopSkip(); if (_waitCoroutine != null) { Main.Current.StopCoroutine(_waitCoroutine); _waitCoroutine = null; } EndEvent?.Invoke(); }