示例#1
0
        public override void OnInitialization()
        {
            base.OnInitialization();

            //创建所有已激活的流程对象
            for (int i = 0; i < ActivatedProcedures.Count; i++)
            {
                Type type = GlobalTools.GetTypeInRunTimeAssemblies(ActivatedProcedures[i]);
                if (type != null)
                {
                    if (type.IsSubclassOf(typeof(ProcedureBase)))
                    {
                        if (!_procedureInstances.ContainsKey(type))
                        {
                            _procedureInstances.Add(type, Activator.CreateInstance(type) as ProcedureBase);
                            _procedureTypes.Add(type);
                        }
                    }
                    else
                    {
                        throw new HTFrameworkException(HTFrameworkModule.Procedure, "创建流程失败:流程 " + ActivatedProcedures[i] + " 必须继承至流程基类:ProcedureBase!");
                    }
                }
                else
                {
                    throw new HTFrameworkException(HTFrameworkModule.Procedure, "创建流程失败:丢失流程 " + ActivatedProcedures[i] + "!");
                }
            }
        }
示例#2
0
        private void ActiveComponentSkip()
        {
            Type type = GlobalTools.GetTypeInRunTimeAssemblies(StringValue);

            if (type != null)
            {
                Component component = Target.GetComponent(type);
                Behaviour behaviour = component as Behaviour;
                Collider  collider  = component as Collider;
                Renderer  renderer  = component as Renderer;
                if (behaviour)
                {
                    behaviour.enabled = BoolValue;
                }
                else if (collider)
                {
                    collider.enabled = BoolValue;
                }
                else if (renderer)
                {
                    renderer.enabled = BoolValue;
                }
            }
            else
            {
                GlobalTools.LogError(string.Format("未获取到类型 {0} !", StringValue));
            }
        }
示例#3
0
        public override void OnInitialization()
        {
            base.OnInitialization();

            if (IsEnableDebugger)
            {
                //创建调试器
                Type type = GlobalTools.GetTypeInRunTimeAssemblies(DebuggerType);
                if (type != null)
                {
                    if (type == typeof(Debugger) || type.IsSubclassOf(typeof(Debugger)))
                    {
                        _debugger = Activator.CreateInstance(type) as Debugger;
                        _debugger.OnInit(DebuggerSkin);
                    }
                    else
                    {
                        throw new HTFrameworkException(HTFrameworkModule.Debug, "创建调试器失败:调试器类 " + DebuggerType + " 必须继承至:Debugger!");
                    }
                }
                else
                {
                    throw new HTFrameworkException(HTFrameworkModule.Debug, "创建调试器失败:丢失调试器类 " + DebuggerType + "!");
                }
            }
        }
示例#4
0
        public override void OnPreparatory()
        {
            base.OnPreparatory();

            //流程初始化
            foreach (var procedureInstance in _procedureInstances)
            {
                procedureInstance.Value.OnInit();
            }

            //进入默认流程
            if (DefaultProcedure != "")
            {
                Type type = GlobalTools.GetTypeInRunTimeAssemblies(DefaultProcedure);
                if (type != null)
                {
                    if (_procedureInstances.ContainsKey(type))
                    {
                        _currentProcedure = _procedureInstances[type];
                        _currentProcedure.OnEnter(null);
                    }
                    else
                    {
                        throw new HTFrameworkException(HTFrameworkModule.Procedure, "进入流程失败:不存在流程 " + type.Name + " 或者流程未激活!");
                    }
                }
                else
                {
                    throw new HTFrameworkException(HTFrameworkModule.Procedure, "进入流程失败:丢失流程 " + DefaultProcedure + " !");
                }
            }
        }
示例#5
0
 private void FSMSkip()
 {
     if (StringValue != "<None>")
     {
         Target.GetComponent <FSM>().SwitchState(GlobalTools.GetTypeInRunTimeAssemblies(StringValue));
     }
 }
示例#6
0
        /// <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);
            }
        }
示例#7
0
        /// <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);
            }
        }
示例#8
0
        private void BeginCurrentStep()
        {
            _running        = false;
            _currentContent = _stepContents[_currentStep];
            _currentTarget  = _currentContent.Target.GetComponent <StepTarget>();

            //UGUI按钮点击型步骤,注册监听
            if (_currentContent.Trigger == StepTrigger.ButtonClick)
            {
                _isButtonClick = false;
                _currentButton = _currentContent.Target.GetComponent <Button>();
                if (_currentButton)
                {
                    _currentButton.onClick.AddListener(ButtonClickCallback);
                }
                else
                {
                    GlobalTools.LogError("【步骤:" + (_currentStep + 1) + "】的目标丢失Button组件!");
                }
            }
            //状态改变触发类型的步骤,自动重置状态
            else if (_currentContent.Trigger == StepTrigger.StateChange)
            {
                _currentTarget.State = StepTargetState.Normal;
            }

            //创建步骤助手
            if (_currentContent.Helper != "<None>")
            {
                Type type = GlobalTools.GetTypeInRunTimeAssemblies(_currentContent.Helper);
                if (type != null)
                {
                    _currentHelper        = Activator.CreateInstance(type) as StepHelper;
                    _currentHelper.Target = _currentTarget;
                    _currentHelper.Task   = StepHelperTask.Execute;
                    _currentHelper.OnInit();
                }
                else
                {
                    GlobalTools.LogError("【步骤:" + (_currentStep + 1) + "】的助手 " + _currentContent.Helper + " 丢失!");
                }
            }

            Main.m_Controller.TheControlMode = _currentContent.InitialMode;
            Main.m_Controller.SetLookPoint(_currentTarget.transform.position + _currentContent.ViewOffset, true);
            Main.m_Controller.SetLookAngle(_currentContent.BestView, true);

            if (BeginStepEvent != null)
            {
                BeginStepEvent(_currentContent);
            }
        }
示例#9
0
        public override void OnInitialization()
        {
            base.OnInitialization();

            //加载通信协议通道
            for (int i = 0; i < ChannelTypes.Count; i++)
            {
                Type type = GlobalTools.GetTypeInRunTimeAssemblies(ChannelTypes[i]);
                if (type != null)
                {
                    if (type.IsSubclassOf(typeof(ProtocolChannelBase)))
                    {
                        if (!_protocolChannels.ContainsKey(type))
                        {
                            _protocolChannels.Add(type, Activator.CreateInstance(type) as ProtocolChannelBase);
                        }
                    }
                    else
                    {
                        throw new HTFrameworkException(HTFrameworkModule.Network, "加载通信协议通道失败:通信协议通道类 " + ChannelTypes[i] + " 必须实现接口:IProtocolChannel!");
                    }
                }
                else
                {
                    throw new HTFrameworkException(HTFrameworkModule.Network, "加载通信协议通道失败:丢失通信协议通道类 " + ChannelTypes[i] + "!");
                }
            }

            //初始化通道
            foreach (var channel in _protocolChannels)
            {
                channel.Value.OnInitialization();
                channel.Value.SendMessageEvent += (cha) =>
                {
                    SendMessageEvent?.Invoke(cha);
                };
                channel.Value.ReceiveMessageEvent += (cha, message) =>
                {
                    ReceiveMessageEvent?.Invoke(cha, message);
                };
                channel.Value.DisconnectServerEvent += (cha) =>
                {
                    DisconnectServerEvent?.Invoke(cha);
                };
            }
        }
示例#10
0
        private void LicenseInitialization()
        {
            if (IsPermanentLicense)
            {
                _isLicenseEnd  = true;
                _isLicensePass = true;
            }
            else
            {
                if (LicenserType != "<None>")
                {
                    Type type = GlobalTools.GetTypeInRunTimeAssemblies(LicenserType);
                    if (type != null)
                    {
                        if (type.IsSubclassOf(typeof(LicenserBase)))
                        {
                            _licenser = Activator.CreateInstance(type) as LicenserBase;
                            _licenser.OnInitialization();
                        }
                        else
                        {
                            GlobalTools.LogError(string.Format("创建授权者失败:授权者类 {0} 必须继承至基类:LicenserBase!", LicenserType));
                        }
                    }
                    else
                    {
                        GlobalTools.LogError(string.Format("创建授权者失败:丢失授权者类 {0}!", LicenserType));
                    }
                }
                else
                {
                    GlobalTools.LogError("已启用授权验证,但授权者类型不能为 <None>!");
                }

                _promptStyle                  = new GUIStyle();
                _promptStyle.alignment        = TextAnchor.MiddleCenter;
                _promptStyle.normal.textColor = Color.red;
                _promptStyle.fontSize         = 30;

                _isLicenseEnd  = false;
                _isLicensePass = false;
            }
        }
示例#11
0
 private void MainDataAwake()
 {
     if (MainDataType != "<None>")
     {
         Type type = GlobalTools.GetTypeInRunTimeAssemblies(MainDataType);
         if (type != null)
         {
             if (type.IsSubclassOf(typeof(MainData)))
             {
                 _data = Activator.CreateInstance(type) as MainData;
                 _data.OnInit();
             }
             else
             {
                 GlobalTools.LogError("创建全局数据类失败:数据类 " + MainDataType + " 必须继承至基类:MainData!");
             }
         }
         else
         {
             GlobalTools.LogError("创建全局数据类失败:丢失数据类 " + MainDataType + "!");
         }
     }
 }
示例#12
0
 private void MainDataInitialization()
 {
     if (MainDataType != "<None>")
     {
         Type type = GlobalTools.GetTypeInRunTimeAssemblies(MainDataType);
         if (type != null)
         {
             if (type.IsSubclassOf(typeof(MainDataBase)))
             {
                 _data = Activator.CreateInstance(type) as MainDataBase;
                 _data.OnInitialization();
             }
             else
             {
                 GlobalTools.LogError(string.Format("创建全局数据类失败:数据类 {0} 必须继承至基类:MainDataBase!", MainDataType));
             }
         }
         else
         {
             GlobalTools.LogError(string.Format("创建全局数据类失败:丢失数据类 {0}!", MainDataType));
         }
     }
 }
示例#13
0
        private IEnumerator SkipStepCoroutine(int index)
        {
            _executing = true;
            _skipIndex = index;

            while (_currentStep < _skipIndex)
            {
                _currentContent = _stepContents[_currentStep];
                _currentTarget  = _currentContent.Target.GetComponent <StepTarget>();
                _currentContent.Skip(this);

                Main.m_Controller.TheControlMode = _currentContent.InitialMode;
                Main.m_Controller.SetLookPoint(_currentTarget.transform.position + _currentContent.ViewOffset, false);
                Main.m_Controller.SetLookAngle(_currentContent.BestView, true);

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

                //UGUI按钮点击型步骤,自动执行按钮事件
                if (_currentContent.Trigger == StepTrigger.ButtonClick)
                {
                    if (_currentButton)
                    {
                        _currentButton.onClick.Invoke();
                    }
                    else
                    {
                        _currentButton = _currentContent.Target.GetComponent <Button>();
                        if (_currentButton)
                        {
                            _currentButton.onClick.Invoke();
                        }
                        else
                        {
                            GlobalTools.LogError(string.Format("【步骤:{0}】的目标丢失Button组件!", _currentStep + 1));
                        }
                    }
                    _currentButton = null;
                }

                //创建步骤助手
                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.Skip;
                        _currentHelper.OnInit();
                    }
                    else
                    {
                        GlobalTools.LogError(string.Format("【步骤:{0}】的助手 {1} 丢失!", _currentStep + 1, _currentContent.Helper));
                    }
                }
                //助手执行跳过,等待生命周期结束后销毁助手
                if (_currentHelper != null)
                {
                    _currentHelper.Task = StepHelperTask.Skip;
                    _currentHelper.OnSkip();
                    if (_currentHelper.SkipLifeTime > 0)
                    {
                        yield return(YieldInstructioner.GetWaitForSeconds(_currentHelper.SkipLifeTime / SkipMultiple));
                    }
                    _currentHelper.OnTermination();
                    _currentHelper = null;
                }

                yield return(YieldInstructioner.GetWaitForSeconds(_currentContent.ElapseTime / SkipMultiple));

                _currentStep += 1;
            }

            SkipStepDoneEvent?.Invoke();

            BeginCurrentStep();
        }
示例#14
0
        private void Awake()
        {
            if (IsAutoRegister)
            {
                Main.m_FSM.RegisterFSM(this);
            }
            //加载数据类
            if (Data != "<None>")
            {
                Type type = GlobalTools.GetTypeInRunTimeAssemblies(Data);
                if (type != null)
                {
                    if (type.IsSubclassOf(typeof(FSMData)))
                    {
                        _data = Activator.CreateInstance(type) as FSMData;
                        _data.StateMachine = this;
                        _data.OnInit();
                    }
                    else
                    {
                        GlobalTools.LogError(string.Format("创建数据类失败:数据类 {0} 必须继承至有限状态机数据基类:FSMData!", Data));
                    }
                }
                else
                {
                    GlobalTools.LogError(string.Format("创建数据类失败:丢失数据类 {0}!", Data));
                }
            }
            //加载所有状态
            for (int i = 0; i < States.Count; i++)
            {
                Type type = GlobalTools.GetTypeInRunTimeAssemblies(States[i]);
                if (type != null)
                {
                    if (type.IsSubclassOf(typeof(FiniteState)))
                    {
                        if (!_stateInstances.ContainsKey(type))
                        {
                            FiniteState state = Activator.CreateInstance(type) as FiniteState;
                            state.StateMachine = this;
                            state.OnInit();
                            _stateInstances.Add(type, state);
                        }
                    }
                    else
                    {
                        GlobalTools.LogError(string.Format("加载有限状态失败:有限状态 {0} 必须继承至有限状态基类:FiniteState!", States[i]));
                    }
                }
                else
                {
                    GlobalTools.LogError(string.Format("加载有限状态失败:丢失有限状态 {0}!", States[i]));
                }
            }
            //进入默认状态
            if (DefaultState == "" || _stateInstances.Count <= 0)
            {
                GlobalTools.LogError(string.Format("有限状态机 {0} 的状态为空!或未指定默认状态!", Name));
                return;
            }
            Type dtype = GlobalTools.GetTypeInRunTimeAssemblies(DefaultState);

            if (dtype != null)
            {
                if (_stateInstances.ContainsKey(dtype))
                {
                    _currentState = _stateInstances[dtype];
                    _currentState.OnEnter();
                }
                else
                {
                    GlobalTools.LogError(string.Format("切换状态失败:有限状态机 {0} 不存在状态 {1}!", Name, dtype.Name));
                }
            }
            else
            {
                GlobalTools.LogError(string.Format("切换状态失败:丢失有限状态 {0}!", DefaultState));
            }
        }
示例#15
0
        //跳过到指定步骤
        private IEnumerator SkipStepCoroutine(int index)
        {
            _executing       = true;
            _skipTargetIndex = index;

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

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

                //UGUI按钮点击型步骤,自动执行按钮事件
                if (_currentContent.Trigger == StepTrigger.ButtonClick)
                {
                    if (_currentButton)
                    {
                        _currentButton.onClick.Invoke();
                        _currentButton.onClick.RemoveListener(ButtonClickCallback);
                    }
                    else
                    {
                        _currentButton = _currentContent.Target.GetComponent <Button>();
                        if (_currentButton)
                        {
                            _currentButton.onClick.Invoke();
                        }
                        else
                        {
                            GlobalTools.LogError(string.Format("步骤控制器:【步骤:{0}】【{1}】的目标丢失Button组件!", _currentStepIndex + 1, _currentContent.Name));
                        }
                    }
                    _currentButton = null;
                }

                //创建步骤助手
                if (_currentHelper == null && _currentContent.Helper != "<None>")
                {
                    Type type = GlobalTools.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.Skip;
                        _currentHelper.OnInit();
                    }
                    else
                    {
                        GlobalTools.LogError(string.Format("步骤控制器:【步骤:{0}】【{1}】的助手 {2} 丢失!", _currentStepIndex + 1, _currentContent.Name, _currentContent.Helper));
                    }
                }
                //助手执行跳过,等待生命周期结束后销毁助手
                if (_currentHelper != null)
                {
                    _currentHelper.Task = StepHelperTask.Skip;
                    _currentHelper.OnSkip();
                    if (_currentHelper.SkipLifeTime > 0)
                    {
                        yield return(YieldInstructioner.GetWaitForSeconds(_currentHelper.SkipLifeTime / SkipMultiple));
                    }
                    _currentHelper.OnTermination();
                    _currentHelper = null;
                }

                yield return(YieldInstructioner.GetWaitForSeconds(_currentContent.ElapseTime / SkipMultiple));

                _currentStepIndex += 1;
            }

            SkipStepDoneEvent?.Invoke();

            yield return(WaitCoroutine(BeginCurrentStep, 0));
        }
示例#16
0
        //步骤开始
        private void BeginCurrentStep()
        {
            _executing      = false;
            _currentContent = _stepContents[_currentStepIndex];
            _currentTarget  = _currentContent.Target.GetComponent <StepTarget>();

            //UGUI按钮点击型步骤,注册监听
            if (_currentContent.Trigger == StepTrigger.ButtonClick)
            {
                _isButtonClick = false;
                _currentButton = _currentTarget.GetComponent <Button>();
                if (_currentButton)
                {
                    _currentButton.onClick.AddListener(ButtonClickCallback);
                }
                else
                {
                    GlobalTools.LogError(string.Format("步骤控制器:【步骤:{0}】【{1}】的目标丢失Button组件!", _currentStepIndex + 1, _currentContent.Name));
                }
            }
            //状态改变触发类型的步骤,自动重置状态
            else if (_currentContent.Trigger == StepTrigger.StateChange)
            {
                _currentTarget.State = StepTargetState.Normal;
            }

            //创建步骤助手
            if (_currentContent.Helper != "<None>")
            {
                Type type = GlobalTools.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.Execute;
                    _currentHelper.OnInit();
                }
                else
                {
                    GlobalTools.LogError(string.Format("步骤控制器:【步骤:{0}】【{1}】的助手 {2} 丢失!", _currentStepIndex + 1, _currentContent.Name, _currentContent.Helper));
                }
            }

            //未激活的步骤自动跳过
            if (_stepContentEnables.ContainsKey(_currentContent.GUID))
            {
                BeginStepEvent?.Invoke(_currentContent, _stepContentEnables[_currentContent.GUID]);
                if (!_stepContentEnables[_currentContent.GUID])
                {
                    Main.Current.StartCoroutine(SkipCurrentStepCoroutine());
                }
            }
            else
            {
                BeginStepEvent?.Invoke(_currentContent, false);
            }
        }
示例#17
0
        private void Awake()
        {
            Main.m_FSM.RegisterFSM(this);
            //加载数据类
            if (Data != "<None>")
            {
                Type type = GlobalTools.GetTypeInRunTimeAssemblies(Data);
                if (type != null)
                {
                    if (type.BaseType == typeof(FSMData))
                    {
                        _data = Activator.CreateInstance(type) as FSMData;
                        _data.StateMachine = this;
                        _data.OnInit();
                    }
                    else
                    {
                        GlobalTools.LogError("创建数据类失败:数据类 " + Data + " 必须继承至有限状态机数据基类:FSMData!");
                    }
                }
                else
                {
                    GlobalTools.LogError("创建数据类失败:丢失数据类 " + Data + "!");
                }
            }
            //加载所有状态
            for (int i = 0; i < States.Count; i++)
            {
                Type type = GlobalTools.GetTypeInRunTimeAssemblies(States[i]);
                if (type != null)
                {
                    if (type.BaseType == typeof(FiniteState))
                    {
                        if (!_stateInstances.ContainsKey(type))
                        {
                            FiniteState state = Activator.CreateInstance(type) as FiniteState;
                            state.StateMachine = this;
                            state.OnInit();
                            _stateInstances.Add(type, state);
                        }
                    }
                    else
                    {
                        GlobalTools.LogError("加载有限状态失败:有限状态 " + States[i] + " 必须继承至有限状态基类:FiniteState!");
                    }
                }
                else
                {
                    GlobalTools.LogError("加载有限状态失败:丢失有限状态 " + States[i] + "!");
                }
            }
            //进入默认状态
            if (DefaultState == "" || _stateInstances.Count <= 0)
            {
                GlobalTools.LogError("有限状态机 " + Name + " 的状态为空!或未指定默认状态!");
                return;
            }
            Type dtype = GlobalTools.GetTypeInRunTimeAssemblies(DefaultState);

            if (dtype != null)
            {
                if (_stateInstances.ContainsKey(dtype))
                {
                    _currentState = _stateInstances[dtype];
                    _currentState.OnEnter();
                }
                else
                {
                    GlobalTools.LogError("切换状态失败:有限状态机 " + Name + " 不存在状态 " + dtype.Name + "!");
                }
            }
            else
            {
                GlobalTools.LogError("切换状态失败:丢失有限状态 " + DefaultState + "!");
            }
        }
示例#18
0
 private void Awake()
 {
     if (IsAutoRegister)
     {
         Main.m_FSM.RegisterFSM(this);
     }
     //加载数据类
     if (Data != "<None>")
     {
         Type type = GlobalTools.GetTypeInRunTimeAssemblies(Data);
         if (type != null)
         {
             if (type.IsSubclassOf(typeof(FSMDataBase)))
             {
                 _data = Activator.CreateInstance(type) as FSMDataBase;
                 _data.StateMachine = this;
                 _data.OnInit();
             }
             else
             {
                 throw new HTFrameworkException(HTFrameworkModule.FSM, "创建有限状态机数据类失败:数据类 " + Data + " 必须继承至有限状态机数据基类:FSMDataBase!");
             }
         }
         else
         {
             throw new HTFrameworkException(HTFrameworkModule.FSM, "创建有限状态机数据类失败:丢失数据类 " + Data + " !");
         }
     }
     //加载所有状态
     for (int i = 0; i < States.Count; i++)
     {
         Type type = GlobalTools.GetTypeInRunTimeAssemblies(States[i]);
         if (type != null)
         {
             if (type.IsSubclassOf(typeof(FiniteStateBase)))
             {
                 if (!_stateInstances.ContainsKey(type))
                 {
                     FiniteStateBase state = Activator.CreateInstance(type) as FiniteStateBase;
                     state.StateMachine = this;
                     state.OnInit();
                     _stateInstances.Add(type, state);
                 }
             }
             else
             {
                 throw new HTFrameworkException(HTFrameworkModule.FSM, "加载有限状态失败:有限状态类 " + States[i] + " 必须继承至有限状态基类:FiniteStateBase!");
             }
         }
         else
         {
             throw new HTFrameworkException(HTFrameworkModule.FSM, "加载有限状态失败:丢失有限状态类 " + States[i] + " !");
         }
     }
     //设置默认状态、最终状态
     if (DefaultState == "" || FinalState == "" || _stateInstances.Count <= 0)
     {
         throw new HTFrameworkException(HTFrameworkModule.FSM, "有限状态机 " + Name + " 的状态为空!或未指定默认状态、最终状态!");
     }
     _defaultState = GlobalTools.GetTypeInRunTimeAssemblies(DefaultState);
     if (_defaultState == null)
     {
         throw new HTFrameworkException(HTFrameworkModule.FSM, "有限状态机 " + Name + " 丢失了默认状态 " + DefaultState + "!");
     }
     _finalState = GlobalTools.GetTypeInRunTimeAssemblies(FinalState);
     if (_finalState == null)
     {
         throw new HTFrameworkException(HTFrameworkModule.FSM, "有限状态机 " + Name + " 丢失了最终状态 " + FinalState + "!");
     }
 }
示例#19
0
        private IEnumerator SkipCurrentStepCoroutine()
        {
            _running = true;

            Main.m_Controller.TheControlMode = _currentContent.InitialMode;
            Main.m_Controller.SetLookPoint(_currentTarget.transform.position + _currentContent.ViewOffset, false);
            Main.m_Controller.SetLookAngle(_currentContent.BestView, true);

            if (SkipStepEvent != null)
            {
                SkipStepEvent(_currentContent);
            }

            //UGUI按钮点击型步骤,自动执行按钮事件
            if (_currentContent.Trigger == StepTrigger.ButtonClick)
            {
                if (_currentButton)
                {
                    _currentButton.onClick.Invoke();
                }
                else
                {
                    _currentButton = _currentContent.Target.GetComponent <Button>();
                    if (_currentButton)
                    {
                        _currentButton.onClick.Invoke();
                    }
                    else
                    {
                        GlobalTools.LogError("【步骤:" + (_currentStep + 1) + "】的目标丢失Button组件!");
                    }
                }
                _currentButton = null;
            }

            //创建步骤助手
            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.Skip;
                    _currentHelper.OnInit();
                }
                else
                {
                    GlobalTools.LogError("【步骤:" + (_currentStep + 1) + "】的助手 " + _currentContent.Helper + " 丢失!");
                }
            }
            //助手执行跳过,等待生命周期结束后销毁助手
            if (_currentHelper != null)
            {
                _currentHelper.Task = StepHelperTask.Skip;
                _currentHelper.OnSkip();
                if (_currentHelper.SkipLifeTime > 0)
                {
                    yield return(new WaitForSeconds(_currentHelper.SkipLifeTime / SkipMultiple));
                }
                _currentHelper.OnTermination();
                _currentHelper = null;
            }

            _currentContent.Skip(this);

            yield return(new WaitForSeconds(_currentContent.ElapseTime / SkipMultiple));

            ChangeNextStep();
        }