Пример #1
0
        /// <summary>
        /// 进行自动化任务(数据)
        /// </summary>
        private void DoAutomaticTaskOfData(FSMDataBase fsmData)
        {
            if (_isAutomate)
            {
                FieldInfo[] fieldInfos = AutomaticTask.GetAutomaticFields(fsmData.GetType());
                AutomaticTask.ApplyObjectPath(fsmData, fieldInfos);

                if (_isSupportedDataDriver)
                {
                    AutomaticTask.ApplyDataBinding(fsmData, fieldInfos);
                }
            }
        }
Пример #2
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 + "!");
     }
 }
Пример #3
0
 /// <summary>
 /// 应用FSM数据的对象路径定义
 /// </summary>
 /// <param name="fsmData">FSM数据实例</param>
 /// <param name="fieldInfos">所有自动化字段</param>
 public static void ApplyObjectPath(FSMDataBase fsmData, FieldInfo[] fieldInfos)
 {
     ApplyObjectPath(fsmData, fsmData.StateMachine.gameObject, fieldInfos);
 }
Пример #4
0
 /// <summary>
 /// 应用FSM数据的数据绑定
 /// </summary>
 /// <param name="fsmData">FSM数据实例</param>
 /// <param name="fieldInfos">所有自动化字段</param>
 public static void ApplyDataBinding(FSMDataBase fsmData, FieldInfo[] fieldInfos)
 {
     ApplyDataBinding(fsmData, fsmData, fieldInfos);
 }