コード例 #1
0
ファイル: StepMaster.cs プロジェクト: paradisewu/HTFramework
        /// <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);
            }
        }
コード例 #2
0
        /// <summary>
        /// 恢复到指定步骤
        /// </summary>
        /// <param name="stepID">步骤ID</param>
        /// <returns>恢复成功/失败</returns>
        public bool RestoreStep(string stepID)
        {
            if (_running && !_executing)
            {
                if (_pause)
                {
                    return(false);
                }

                if (!_stepContentIndexs.ContainsKey(stepID))
                {
                    return(false);
                }

                int index = _stepContentIndexs[stepID];
                if (index < 0 || index >= _currentStepIndex)
                {
                    return(false);
                }

                CurrentTask = StepHelperTask.Restore;

                while (_currentStepIndex >= index)
                {
                    _currentContent = _stepContents[_currentStepIndex];
                    _currentTarget  = _currentContent.Target.GetComponent <StepTarget>();

                    //创建步骤助手
                    if (_currentHelper == null)
                    {
                        _currentHelper = CreateHelper(_currentContent, StepHelperTask.Restore);
                    }

                    RestoreStepEvent?.Invoke(_currentContent, _stepContentEnables.ContainsKey(_currentContent.GUID) ? _stepContentEnables[_currentContent.GUID] : false);

                    //助手执行恢复
                    if (_currentHelper != null)
                    {
                        _currentHelper.Task = StepHelperTask.Restore;
                        _currentHelper.OnRestore();
                        _currentHelper.OnTermination();
                        _currentHelper = null;
                    }

                    _currentStepIndex -= 1;
                }

                _currentStepIndex = index;
                BeginCurrentStep();
                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #3
0
        /// <summary>
        /// 恢复到指定步骤
        /// </summary>
        /// <param name="stepID">步骤ID</param>
        /// <returns>恢复成功/失败</returns>
        public bool RestoreStep(string stepID)
        {
            if (_running && !_executing)
            {
                if (_pause)
                {
                    return(false);
                }

                if (!_stepContentIndexs.ContainsKey(stepID))
                {
                    return(false);
                }

                int index = _stepContentIndexs[stepID];
                if (index < 0 || index >= _currentStepIndex)
                {
                    return(false);
                }

                while (_currentStepIndex >= index)
                {
                    _currentContent = _stepContents[_currentStepIndex];
                    _currentTarget  = _currentContent.Target.GetComponent <StepTarget>();

                    RestoreStepEvent?.Invoke(_currentContent, _stepContentEnables.ContainsKey(_currentContent.GUID) ? _stepContentEnables[_currentContent.GUID] : false);

                    //创建步骤助手
                    if (_currentHelper == null && _currentContent.Helper != "<None>")
                    {
                        Type type = ReflectionToolkit.GetTypeInRunTimeAssemblies(_currentContent.Helper);
                        if (type != null)
                        {
                            _currentHelper            = Activator.CreateInstance(type) as StepHelper;
                            _currentHelper.Parameters = _currentContent.Parameters;
                            for (int i = 0; i < _currentHelper.Parameters.Count; i++)
                            {
                                if (_currentHelper.Parameters[i].Type == StepParameter.ParameterType.GameObject)
                                {
                                    if (_targets.ContainsKey(_currentHelper.Parameters[i].GameObjectGUID))
                                    {
                                        _currentHelper.Parameters[i].GameObjectValue = _targets[_currentHelper.Parameters[i].GameObjectGUID].gameObject;
                                    }
                                }
                            }
                            _currentHelper.Content = _currentContent;
                            _currentHelper.Target  = _currentTarget;
                            _currentHelper.Task    = StepHelperTask.Restore;
                            _currentHelper.OnInit();
                        }
                        else
                        {
                            Log.Error(string.Format("步骤控制者:【步骤:{0}】的助手 {1} 丢失!", _currentStepIndex + 1, _currentContent.Helper));
                        }
                    }
                    //助手执行恢复
                    if (_currentHelper != null)
                    {
                        _currentHelper.Task = StepHelperTask.Restore;
                        _currentHelper.OnRestore();
                        _currentHelper.OnTermination();
                        _currentHelper = null;
                    }

                    _currentStepIndex -= 1;
                }

                _currentStepIndex = index;
                BeginCurrentStep();
                return(true);
            }
            else
            {
                return(false);
            }
        }