コード例 #1
0
ファイル: FSM.cs プロジェクト: yanngu/HTFramework
 /// <summary>
 /// 附加状态
 /// </summary>
 /// <param name="type">状态类型</param>
 public void AppendState(Type type)
 {
     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, "附加状态失败:有限状态机 " + Name + " 已存在状态 " + type.Name + "!");
     }
 }
コード例 #2
0
 /// <summary>
 /// 附加状态
 /// </summary>
 /// <param name="type">状态类型</param>
 public void AppendState(Type type)
 {
     if (!_stateInstances.ContainsKey(type))
     {
         FiniteStateBase state = Activator.CreateInstance(type) as FiniteStateBase;
         state.StateMachine = this;
         state.OnInit();
         _stateInstances.Add(type, state);
     }
     else
     {
         Log.Warning("附加状态失败:有限状态机 " + Name + " 已存在状态 " + type.Name + "!");
     }
 }
コード例 #3
0
ファイル: FSM.cs プロジェクト: yanngu/HTFramework
 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 + "!");
     }
 }