/// <summary> /// 添加状态 /// </summary> /// <param name="t_StateType">状态的抽象基类类型</param> public void AddState(BaseFSMState t_BaseFSMState) { if (null == t_BaseFSMState) { throw new GameBoxFrameworkException(string.Format("添加的状态不能为空!")); } if (!string.IsNullOrEmpty(t_BaseFSMState.StateName)) { if (IStateMapDataStructure.ContainsKey(t_BaseFSMState.StateName)) { throw new GameBoxFrameworkException(string.Format("状态'{0}'已经存在!", t_BaseFSMState.GetType().Name)); } IStateMapDataStructure.Add(t_BaseFSMState.StateName, t_BaseFSMState); } else { if (IStateMapDataStructure.ContainsKey(t_BaseFSMState.GetType().Name)) { throw new GameBoxFrameworkException(string.Format("状态'{0}'已经存在!", t_BaseFSMState.GetType().Name)); } IStateMapDataStructure.Add(t_BaseFSMState.GetType().Name, t_BaseFSMState); // 如果改状态没有名字,那么改状态就采用状态的类名 } t_BaseFSMState.OnStateInit(this); //初始化状态机 }
/// <summary> /// 添加状态 /// </summary> /// <typeparam name="T">状态的类型</typeparam> public void AddState <T>() where T : BaseFSMState { var t_State = Activator.CreateInstance(typeof(T)) as BaseFSMState; // 如果改状态没有名字,那么改状态就采用状态的类名 if (IStateMapDataStructure.ContainsKey(typeof(T).Name)) { throw new GameBoxFrameworkException(string.Format("状态'{0}'已经存在!", typeof(T).Name)); } IStateMapDataStructure.Add(typeof(T).Name, t_State); t_State.OnStateInit(this); //初始化状态机 }