Beispiel #1
0
        /// <summary>
        /// 助手准备工作
        /// </summary>
        public void OnPreparatory()
        {
            //流程初始化
            foreach (var procedure in Procedures)
            {
                procedure.Value.OnInit();
            }

            //进入默认流程
            if (_defaultProcedure != "")
            {
                Type type = ReflectionToolkit.GetTypeInRunTimeAssemblies(_defaultProcedure);
                if (type != null)
                {
                    if (Procedures.ContainsKey(type))
                    {
                        CurrentProcedure = Procedures[type];
                        CurrentProcedure.OnEnter(null);
                    }
                    else
                    {
                        throw new HTFrameworkException(HTFrameworkModule.Procedure, "进入流程失败:不存在流程 " + type.Name + " 或者流程未激活!");
                    }
                }
                else
                {
                    throw new HTFrameworkException(HTFrameworkModule.Procedure, "进入流程失败:丢失流程 " + _defaultProcedure + " !");
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// 初始化助手
        /// </summary>
        public void OnInitialization()
        {
            ProcedureManager manager = Module as ProcedureManager;

            //创建所有已激活的流程对象
            for (int i = 0; i < manager.ActivatedProcedures.Count; i++)
            {
                Type type = ReflectionToolkit.GetTypeInRunTimeAssemblies(manager.ActivatedProcedures[i]);
                if (type != null)
                {
                    if (type.IsSubclassOf(typeof(ProcedureBase)))
                    {
                        if (!Procedures.ContainsKey(type))
                        {
                            Procedures.Add(type, Activator.CreateInstance(type) as ProcedureBase);
                            ProcedureTypes.Add(type);
                        }
                    }
                    else
                    {
                        throw new HTFrameworkException(HTFrameworkModule.Procedure, "创建流程失败:流程 " + manager.ActivatedProcedures[i] + " 必须继承至流程基类:ProcedureBase!");
                    }
                }
                else
                {
                    throw new HTFrameworkException(HTFrameworkModule.Procedure, "创建流程失败:丢失流程 " + manager.ActivatedProcedures[i] + "!");
                }
            }
            _defaultProcedure = manager.DefaultProcedure;
        }
Beispiel #3
0
 /// <summary>
 /// 创建步骤助手
 /// </summary>
 private StepHelper CreateHelper(StepContent content, StepHelperTask task)
 {
     if (!string.IsNullOrEmpty(content.Helper) && content.Helper != "<None>")
     {
         Type type = ReflectionToolkit.GetTypeInRunTimeAssemblies(content.Helper);
         if (type != null)
         {
             StepHelper helper = Activator.CreateInstance(type) as StepHelper;
             helper.Parameters = content.Parameters;
             for (int i = 0; i < helper.Parameters.Count; i++)
             {
                 if (helper.Parameters[i].Type == StepParameter.ParameterType.GameObject)
                 {
                     if (_targets.ContainsKey(helper.Parameters[i].GameObjectGUID))
                     {
                         helper.Parameters[i].GameObjectValue = _targets[helper.Parameters[i].GameObjectGUID].gameObject;
                     }
                 }
             }
             helper.Content = content;
             helper.Target  = content.Target.GetComponent <StepTarget>();
             helper.Task    = task;
             helper.OnInit();
             return(helper);
         }
         else
         {
             Log.Error(string.Format("步骤控制器:步骤 {0}.{1} 的助手 {2} 丢失!", _currentStepIndex + 1, _currentContent.Name, _currentContent.Helper));
         }
     }
     return(null);
 }
Beispiel #4
0
        internal override void OnInitialization()
        {
            base.OnInitialization();

            //创建所有已激活的流程对象
            for (int i = 0; i < ActivatedProcedures.Count; i++)
            {
                Type type = ReflectionToolkit.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] + "!");
                }
            }
        }
Beispiel #5
0
        private void ActiveComponentSkip()
        {
            Type type = ReflectionToolkit.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
            {
                Log.Error("步骤控制者:未获取到组件类型 " + StringValue + " !");
            }
        }
Beispiel #6
0
 private void FSMSkip()
 {
     if (StringValue != "<None>")
     {
         Target.GetComponent <FSM>().SwitchState(ReflectionToolkit.GetTypeInRunTimeAssemblies(StringValue));
     }
 }
Beispiel #7
0
        internal override void OnInitialization()
        {
            base.OnInitialization();

            if (IsEnableDebugger)
            {
                //创建调试器
                Type type = ReflectionToolkit.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 + "!");
                }
            }
        }
Beispiel #8
0
        /// <summary>
        /// 初始化模块
        /// </summary>
        public virtual void OnInitialization()
        {
            if (HelperType != "<None>")
            {
                Type type = ReflectionToolkit.GetTypeInRunTimeAssemblies(HelperType);
                if (type != null)
                {
                    if (typeof(IInternalModuleHelper).IsAssignableFrom(type))
                    {
                        _helper        = Activator.CreateInstance(type) as H;
                        _helper.Module = this;
                    }
                    else
                    {
                        throw new HTFrameworkException(HTFrameworkModule.Main, "创建内置模块助手失败:内置模块助手类 " + HelperType + " 必须实现该模块对应的助手接口!");
                    }
                }
                else
                {
                    throw new HTFrameworkException(HTFrameworkModule.Main, "创建内置模块助手失败:丢失内置模块助手类 " + HelperType + "!");
                }
            }

            if (_helper != null)
            {
                _helper.OnInitialization();
            }
        }
Beispiel #9
0
        internal override void OnInitialization()
        {
            base.OnInitialization();

            _helper = Helper as IInputHelper;

            //加载输入设备
            Type type = ReflectionToolkit.GetTypeInRunTimeAssemblies(InputDeviceType);

            if (type != null)
            {
                if (type.IsSubclassOf(typeof(InputDeviceBase)))
                {
                    _inputDevice = Activator.CreateInstance(type) as InputDeviceBase;
                }
                else
                {
                    throw new HTFrameworkException(HTFrameworkModule.Input, "加载输入设备失败:输入设备类 " + InputDeviceType + " 必须继承至输入设备基类:InputDeviceBase!");
                }
            }
            else
            {
                throw new HTFrameworkException(HTFrameworkModule.Input, "加载输入设备失败:丢失输入设备类 " + InputDeviceType + "!");
            }
        }
Beispiel #10
0
        internal override void OnPreparatory()
        {
            base.OnPreparatory();

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

            //进入默认流程
            if (DefaultProcedure != "")
            {
                Type type = ReflectionToolkit.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 + " !");
                }
            }
        }
Beispiel #11
0
 /// <summary>
 /// 更新步骤助手的名称
 /// </summary>
 internal void RefreshHelperName()
 {
     if (Helper == "<None>")
     {
         HelperName = "未设置助手";
     }
     else
     {
         Type type = ReflectionToolkit.GetTypeInRunTimeAssemblies(Helper);
         if (type == null)
         {
             HelperName = "无效的助手";
         }
         else
         {
             CustomHelperAttribute helper = type.GetCustomAttribute <CustomHelperAttribute>();
             if (helper != null)
             {
                 HelperName = helper.Name;
             }
             else
             {
                 HelperName = type.FullName;
             }
         }
     }
 }
        protected override void OnInspectorRuntimeGUI()
        {
            base.OnInspectorRuntimeGUI();

            if (Targets.Length > 1)
            {
                return;
            }

            GUILayout.BeginHorizontal();
            string currentStateName = "<None>";

            if (Target.CurrentState != null)
            {
                FiniteStateNameAttribute nameAttribute = Target.CurrentState.GetType().GetCustomAttribute <FiniteStateNameAttribute>();
                currentStateName = nameAttribute != null ? nameAttribute.Name : Target.CurrentState.GetType().FullName;
            }
            GUILayout.Label("Current State: " + currentStateName);
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label("States: " + _stateNames.Count);
            GUILayout.EndHorizontal();

            foreach (var state in _stateNames)
            {
                GUILayout.BeginHorizontal();
                GUILayout.Space(20);
                GUILayout.Label(state.Value);
                GUILayout.FlexibleSpace();
                GUI.enabled = Target.CurrentState.GetType().FullName != state.Key;
                if (GUILayout.Button("Switch", EditorStyles.miniButton))
                {
                    Target.SwitchState(ReflectionToolkit.GetTypeInRunTimeAssemblies(state.Key));
                }
                GUI.enabled = true;
                GUILayout.EndHorizontal();
            }

            GUILayout.BeginHorizontal();
            if (GUILayout.Button("Renewal", EditorStyles.miniButtonLeft))
            {
                Target.Renewal();
            }
            if (GUILayout.Button("Final", EditorStyles.miniButtonRight))
            {
                Target.Final();
            }
            GUILayout.EndHorizontal();
        }
Beispiel #13
0
        internal override void OnInitialization()
        {
            base.OnInitialization();

            //加载通信协议通道
            for (int i = 0; i < ChannelTypes.Count; i++)
            {
                Type type = ReflectionToolkit.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);
                };
            }
        }
 /// <summary>
 /// 加载输入设备
 /// </summary>
 /// <param name="deviceType">输入设备类型</param>
 public void LoadDevice(string deviceType)
 {
     Type type = ReflectionToolkit.GetTypeInRunTimeAssemblies(deviceType);
     if (type != null)
     {
         if (type.IsSubclassOf(typeof(InputDeviceBase)))
         {
             Device = Activator.CreateInstance(type) as InputDeviceBase;
         }
         else
         {
             throw new HTFrameworkException(HTFrameworkModule.Input, "加载输入设备失败:输入设备类 " + deviceType + " 必须继承至输入设备基类:InputDeviceBase!");
         }
     }
     else
     {
         throw new HTFrameworkException(HTFrameworkModule.Input, "加载输入设备失败:丢失输入设备类 " + deviceType + "!");
     }
 }
Beispiel #15
0
        private void LicenseInitialization()
        {
            if (IsPermanentLicense)
            {
                _isLicenseEnd  = true;
                _isLicensePass = true;
            }
            else
            {
                if (LicenserType != "<None>")
                {
                    Type type = ReflectionToolkit.GetTypeInRunTimeAssemblies(LicenserType);
                    if (type != null)
                    {
                        if (type.IsSubclassOf(typeof(LicenserBase)))
                        {
                            _licenser = Activator.CreateInstance(type) as LicenserBase;
                            _licenser.OnInitialization();
                        }
                        else
                        {
                            Log.Error(string.Format("创建授权者失败:授权者类 {0} 必须继承至基类:LicenserBase!", LicenserType));
                        }
                    }
                    else
                    {
                        Log.Error(string.Format("创建授权者失败:丢失授权者类 {0}!", LicenserType));
                    }
                }
                else
                {
                    Log.Error("已启用授权验证,但授权者类型不能为 <None>!");
                }

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

                _isLicenseEnd  = false;
                _isLicensePass = false;
            }
        }
        /// <summary>
        /// 加载通信管道
        /// </summary>
        /// <param name="channelTypes">启用的通信协议通道类型</param>
        public void LoadProtocolChannels(List <string> channelTypes)
        {
            for (int i = 0; i < channelTypes.Count; i++)
            {
                Type type = ReflectionToolkit.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] + " 必须继承至基类:ProtocolChannelBase!");
                    }
                }
                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);
                };
            }
        }
        /// <summary>
        /// 助手准备工作
        /// </summary>
        public void OnPreparatory()
        {
            //流程初始化
            foreach (var procedure in Procedures)
            {
                procedure.Value.OnInit();
            }

            //进入默认流程
            if (!string.IsNullOrEmpty(_defaultProcedure))
            {
                Type type = ReflectionToolkit.GetTypeInRunTimeAssemblies(_defaultProcedure);
                if (type != null)
                {
                    SwitchProcedure(type);
                }
                else
                {
                    throw new HTFrameworkException(HTFrameworkModule.Procedure, "进入流程失败:丢失流程 " + _defaultProcedure + " !");
                }
            }
        }
Beispiel #18
0
 private void MainDataInitialization()
 {
     if (MainDataType != "<None>")
     {
         Type type = ReflectionToolkit.GetTypeInRunTimeAssemblies(MainDataType);
         if (type != null)
         {
             if (type.IsSubclassOf(typeof(MainDataBase)))
             {
                 _mainData = Activator.CreateInstance(type) as MainDataBase;
                 _mainData.OnInitialization();
             }
             else
             {
                 Log.Error(string.Format("创建全局数据类失败:数据类 {0} 必须继承至基类:MainDataBase!", MainDataType));
             }
         }
         else
         {
             Log.Error(string.Format("创建全局数据类失败:丢失数据类 {0}!", MainDataType));
         }
     }
 }
Beispiel #19
0
        protected override void Awake()
        {
            base.Awake();

            if (IsAutoRegister)
            {
                Main.m_FSM.RegisterFSM(this);
            }
            //加载数据类
            if (Data != "<None>")
            {
                Type type = ReflectionToolkit.GetTypeInRunTimeAssemblies(Data);
                if (type != null)
                {
                    if (type.IsSubclassOf(typeof(FSMDataBase)))
                    {
                        CurrentData = Activator.CreateInstance(type) as FSMDataBase;
                        CurrentData.StateMachine = this;
                    }
                    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 = ReflectionToolkit.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;
                            _stateInstances.Add(type, state);
                        }
                    }
                    else
                    {
                        throw new HTFrameworkException(HTFrameworkModule.FSM, "加载有限状态失败:有限状态类 " + States[i] + " 必须继承至有限状态基类:FiniteStateBase!");
                    }
                }
                else
                {
                    throw new HTFrameworkException(HTFrameworkModule.FSM, "加载有限状态失败:丢失有限状态类 " + States[i] + " !");
                }
            }
            //设置默认状态、最终状态
            if (string.IsNullOrEmpty(DefaultState) || string.IsNullOrEmpty(FinalState) || _stateInstances.Count <= 0)
            {
                throw new HTFrameworkException(HTFrameworkModule.FSM, "有限状态机 " + Name + " 的状态为空!或未指定默认状态、最终状态!");
            }
            _defaultState = ReflectionToolkit.GetTypeInRunTimeAssemblies(DefaultState);
            if (_defaultState == null)
            {
                throw new HTFrameworkException(HTFrameworkModule.FSM, "有限状态机 " + Name + " 丢失了默认状态 " + DefaultState + "!");
            }
            _finalState = ReflectionToolkit.GetTypeInRunTimeAssemblies(FinalState);
            if (_finalState == null)
            {
                throw new HTFrameworkException(HTFrameworkModule.FSM, "有限状态机 " + Name + " 丢失了最终状态 " + FinalState + "!");
            }
            _isAutomate            = CurrentData != null ? CurrentData.IsAutomate : false;
            _isSupportedDataDriver = CurrentData != null ? CurrentData.IsSupportedDataDriver : false;

            DoAutomaticTask();
        }
        protected override void OnDefaultEnable()
        {
            base.OnDefaultEnable();

            if (Targets.Length > 1)
            {
                return;
            }

            _stateGC           = new GUIContent();
            _stateGC.image     = EditorGUIUtility.IconContent("AnimatorState Icon").image;
            _addGC             = new GUIContent();
            _addGC.image       = EditorGUIUtility.IconContent("d_Toolbar Plus More").image;
            _addGC.tooltip     = "Add a new state";
            _removeGC          = new GUIContent();
            _removeGC.image    = EditorGUIUtility.IconContent("d_Toolbar Minus").image;
            _removeGC.tooltip  = "Remove select state";
            _defaultGC         = new GUIContent();
            _defaultGC.image   = EditorGUIUtility.IconContent("TimelineEditModeRippleON").image;
            _defaultGC.tooltip = "Default state";
            _finalGC           = new GUIContent();
            _finalGC.image     = EditorGUIUtility.IconContent("TimelineEditModeReplaceON").image;
            _finalGC.tooltip   = "Final state";
            _editGC            = new GUIContent();
            _editGC.image      = EditorGUIUtility.IconContent("d_editicon.sml").image;
            _editGC.tooltip    = "Edit state script";

            _states    = GetProperty("States");
            _stateList = new ReorderableList(serializedObject, _states, true, true, false, false);
            _stateList.drawHeaderCallback = (Rect rect) =>
            {
                Rect sub = rect;
                sub.Set(rect.x, rect.y, 200, rect.height);
                GUI.Label(sub, "Enabled States:");

                if (!EditorApplication.isPlaying)
                {
                    sub.Set(rect.x + rect.width - 40, rect.y - 2, 20, 20);
                    if (GUI.Button(sub, _addGC, "InvisibleButton"))
                    {
                        GenericMenu gm    = new GenericMenu();
                        List <Type> types = ReflectionToolkit.GetTypesInRunTimeAssemblies(type =>
                        {
                            return(type.IsSubclassOf(typeof(FiniteStateBase)) && !type.IsAbstract);
                        });
                        for (int i = 0; i < types.Count; i++)
                        {
                            int    j         = i;
                            string stateName = types[j].FullName;
                            FiniteStateNameAttribute fsmAtt = types[j].GetCustomAttribute <FiniteStateNameAttribute>();
                            if (fsmAtt != null)
                            {
                                stateName = fsmAtt.Name;
                            }

                            if (Target.States.Contains(types[j].FullName))
                            {
                                gm.AddDisabledItem(new GUIContent(stateName));
                            }
                            else
                            {
                                gm.AddItem(new GUIContent(stateName), false, () =>
                                {
                                    Undo.RecordObject(target, "Add FSM State");
                                    Target.States.Add(types[j].FullName);
                                    if (string.IsNullOrEmpty(Target.DefaultState))
                                    {
                                        Target.DefaultState = Target.States[0];
                                    }
                                    if (string.IsNullOrEmpty(Target.FinalState))
                                    {
                                        Target.FinalState = Target.States[0];
                                    }
                                    HasChanged();
                                });
                            }
                        }
                        gm.ShowAsContext();
                    }

                    sub.Set(rect.x + rect.width - 20, rect.y - 2, 20, 20);
                    GUI.enabled = _stateList.index >= 0 && _stateList.index < Target.States.Count;
                    if (GUI.Button(sub, _removeGC, "InvisibleButton"))
                    {
                        Undo.RecordObject(target, "Delete FSM State");

                        if (Target.DefaultState == Target.States[_stateList.index])
                        {
                            Target.DefaultState = null;
                        }
                        if (Target.FinalState == Target.States[_stateList.index])
                        {
                            Target.FinalState = null;
                        }

                        Target.States.RemoveAt(_stateList.index);

                        if (string.IsNullOrEmpty(Target.DefaultState) && Target.States.Count > 0)
                        {
                            Target.DefaultState = Target.States[0];
                        }
                        if (string.IsNullOrEmpty(Target.FinalState) && Target.States.Count > 0)
                        {
                            Target.FinalState = Target.States[0];
                        }

                        HasChanged();
                    }
                    GUI.enabled = true;
                }
            };
            _stateList.drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) =>
            {
                if (index >= 0 && index < Target.States.Count)
                {
                    SerializedProperty property  = _states.GetArrayElementAtIndex(index);
                    string             stateType = property.stringValue;
                    if (!_stateNames.ContainsKey(stateType))
                    {
                        Type type = ReflectionToolkit.GetTypeInRunTimeAssemblies(stateType);
                        if (type != null)
                        {
                            string stateName = type.FullName;
                            FiniteStateNameAttribute fsmAtt = type.GetCustomAttribute <FiniteStateNameAttribute>();
                            if (fsmAtt != null)
                            {
                                stateName = fsmAtt.Name;
                            }
                            _stateNames.Add(stateType, stateName);
                        }
                        else
                        {
                            _stateNames.Add(stateType, "<Missing>");
                        }
                    }

                    Rect subrect = rect;
                    subrect.Set(rect.x, rect.y + 2, rect.width, 16);
                    _stateGC.text = _stateNames[stateType];
                    GUI.color     = _stateGC.text != "<Missing>" ? Color.white : Color.red;
                    GUI.Label(subrect, _stateGC);
                    GUI.color = Color.white;

                    int size = 20;
                    if (Target.FinalState == stateType)
                    {
                        subrect.Set(rect.x + rect.width - size, rect.y + 2, 20, 16);
                        if (GUI.Button(subrect, _finalGC, "InvisibleButton"))
                        {
                            GenericMenu gm = new GenericMenu();
                            foreach (var state in _stateNames)
                            {
                                gm.AddItem(new GUIContent(state.Value), Target.FinalState == state.Key, () =>
                                {
                                    Undo.RecordObject(target, "Set FSM Final State");
                                    Target.FinalState = state.Key;
                                    HasChanged();
                                });
                            }
                            gm.ShowAsContext();
                        }
                        size += 20;
                    }
                    if (Target.DefaultState == stateType)
                    {
                        subrect.Set(rect.x + rect.width - size, rect.y + 2, 20, 16);
                        if (GUI.Button(subrect, _defaultGC, "InvisibleButton"))
                        {
                            GenericMenu gm = new GenericMenu();
                            foreach (var state in _stateNames)
                            {
                                gm.AddItem(new GUIContent(state.Value), Target.DefaultState == state.Key, () =>
                                {
                                    Undo.RecordObject(target, "Set FSM Default State");
                                    Target.DefaultState = state.Key;
                                    HasChanged();
                                });
                            }
                            gm.ShowAsContext();
                        }
                        size += 20;
                    }
                    if (isActive && isFocused)
                    {
                        subrect.Set(rect.x + rect.width - size, rect.y, 20, 20);
                        if (GUI.Button(subrect, _editGC, "InvisibleButton"))
                        {
                            MonoScriptToolkit.OpenMonoScript(stateType);
                        }
                        size += 20;
                    }
                }
            };
            _stateList.drawElementBackgroundCallback = (Rect rect, int index, bool isActive, bool isFocused) =>
            {
                if (Event.current.type == EventType.Repaint)
                {
                    GUIStyle gUIStyle = (index % 2 != 0) ? "CN EntryBackEven" : "CN EntryBackodd";
                    gUIStyle    = (!isActive && !isFocused) ? gUIStyle : "RL Element";
                    rect.x     += 2;
                    rect.width -= 6;
                    gUIStyle.Draw(rect, false, isActive, isActive, isFocused);
                }
            };
            _stateNames = new Dictionary <string, string>();

            if (Target.Args == null)
            {
                FSMArgsBase args = Target.GetComponent <FSMArgsBase>();
                if (args != null)
                {
                    Target.Args = args;
                    HasChanged();
                }
            }
            if (Target.Args != null)
            {
                Target.Args.hideFlags = HideFlags.HideInHierarchy | HideFlags.HideInInspector;
            }
        }
Beispiel #21
0
        /// <summary>
        /// 跳过当前步骤(立即模式)
        /// </summary>
        private void SkipCurrentStepImmediateCoroutine()
        {
            _executing = true;

            SkipStepImmediateEvent?.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 = _currentTarget.GetComponent <Button>();
                    if (_currentButton)
                    {
                        _currentButton.onClick.Invoke();
                    }
                    else
                    {
                        Log.Error(string.Format("步骤控制器:【步骤:{0}】【{1}】的目标丢失Button组件!", _currentStepIndex + 1, _currentContent.Name));
                    }
                }
                _currentButton = null;
            }

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

            _currentContent.SkipImmediate();

            //助手执行跳过,等待生命周期结束后销毁助手
            if (_currentHelper != null)
            {
                _currentHelper.Task = StepHelperTask.SkipImmediate;
                _currentHelper.OnSkipImmediate();
                _currentHelper.OnTermination();
                _currentHelper = null;
            }

            ChangeNextStep();
        }
Beispiel #22
0
 private void Awake()
 {
     if (IsAutoRegister)
     {
         Main.m_FSM.RegisterFSM(this);
     }
     //加载数据类
     if (Data != "<None>")
     {
         Type type = ReflectionToolkit.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 = ReflectionToolkit.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 = ReflectionToolkit.GetTypeInRunTimeAssemblies(DefaultState);
     if (_defaultState == null)
     {
         throw new HTFrameworkException(HTFrameworkModule.FSM, "有限状态机 " + Name + " 丢失了默认状态 " + DefaultState + "!");
     }
     _finalState = ReflectionToolkit.GetTypeInRunTimeAssemblies(FinalState);
     if (_finalState == null)
     {
         throw new HTFrameworkException(HTFrameworkModule.FSM, "有限状态机 " + Name + " 丢失了最终状态 " + FinalState + "!");
     }
 }
Beispiel #23
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);
            }
        }
Beispiel #24
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
                {
                    Log.Error(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 = 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.Execute;
                    _currentHelper.OnInit();
                }
                else
                {
                    Log.Error(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);
            }
        }
Beispiel #25
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
                        {
                            Log.Error(string.Format("步骤控制器:【步骤:{0}】【{1}】的目标丢失Button组件!", _currentStepIndex + 1, _currentContent.Name));
                        }
                    }
                    _currentButton = null;
                }

                //创建步骤助手
                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.Skip;
                        _currentHelper.OnInit();
                    }
                    else
                    {
                        Log.Error(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();

            _waitCoroutine = Main.Current.StartCoroutine(WaitCoroutine(BeginCurrentStep, 0));
        }