Beispiel #1
0
        /// <summary>
        /// 获取条件
        /// </summary>
        /// <typeparam name="T">基础状态机条件</typeparam>
        /// <returns>状态机条件</returns>
        public T GetCondition <T>() where T : BaseFSMCondition
        {
            BaseFSMCondition t_Condition;

            IConditionMapDataStructure.TryGetValue(typeof(T).Name, out t_Condition);
            return(t_Condition as T);
        }
Beispiel #2
0
 /// <summary>
 /// 移除状态
 /// </summary>
 /// <param name="t_StateType">状态类型</param>
 public void RemoveCondition(Type t_ConditionType)
 {
     IConditionMapDataStructure.Foreach((key, value) => {
         if (value.GetType() == t_ConditionType)
         {
             IConditionMapDataStructure.Remove(key);
             value.OnConditionDestroy(this);
         }
     });
 }
Beispiel #3
0
 /// <summary>
 /// 移除状态机条件
 /// </summary>
 /// <typeparam name="T"></typeparam>
 public void RemoveCondition <T>() where T : BaseFSMCondition
 {
     IConditionMapDataStructure.Foreach((key, value) => {
         if (value is T)
         {
             IStateMapDataStructure.Remove(key);
             value.OnConditionDestroy(this);
         }
     });
 }
Beispiel #4
0
        /// <summary>
        /// 获取所有条件
        /// </summary>
        /// <returns>基础条件实例数组</returns>
        public BaseFSMCondition[] GetAllCondition()
        {
            BaseFSMCondition[] t_BaseConditions = new BaseFSMCondition[IConditionMapDataStructure.Count];
            var t_ConditionMaps = IConditionMapDataStructure.ToArray();

            for (int i = 0; i < t_ConditionMaps.Length; i++)
            {
                t_BaseConditions[i] = t_ConditionMaps[i].Value;
            }
            return(t_BaseConditions);
        }
Beispiel #5
0
 /// <summary>
 /// 添加状态机条件
 /// </summary>
 /// <param name="t_BaseFSMCondition">状态机条件类型</param>
 public void AddCondition(BaseFSMCondition t_BaseFSMCondition)
 {
     if (!IConditionMapDataStructure.ContainsValue(t_BaseFSMCondition))
     {
         IConditionMapDataStructure.Add(t_BaseFSMCondition.GetType().Name, t_BaseFSMCondition);
     }
     else
     {
         throw new GameBoxFrameworkException(string.Format("已经存在'{0}'条件", t_BaseFSMCondition.GetType().Name));
     }
 }
Beispiel #6
0
 /// <summary>
 /// 添加状态机条件
 /// </summary>
 /// <typeparam name="T">状态机条件</typeparam>
 public void AddCondition <T>() where T : BaseFSMCondition
 {
     if (!IConditionMapDataStructure.ContainsKey(typeof(T).Name))
     {
         IConditionMapDataStructure.Add(typeof(T).Name, Activator.CreateInstance <T>());
     }
     else
     {
         throw new GameBoxFrameworkException(string.Format("已经存在'{0}'条件", typeof(T).Name));
     }
 }
Beispiel #7
0
 /// <summary>
 /// 轮询更新条件
 /// </summary>
 private void UpdateCondition()
 {
     IConditionMapDataStructure.Foreach((key, value) => {
         if (value.OnConditionLoop(this))
         {
             if (null != value.StateType)
             {
                 ChangeState(value.StateType);
             }
         }
     });
 }
Beispiel #8
0
        /// <summary>
        /// 移除状态机条件
        /// </summary>
        /// <param name="t_FSMName">状态机条件的类名</param>
        public void RemoveCondition(string t_ConditionName)
        {
            BaseFSMCondition value;

            IConditionMapDataStructure.TryGetValue(t_ConditionName, out value);

            if (!IStateMapDataStructure.ContainsKey(t_ConditionName))
            {
                IStateMapDataStructure.Remove(t_ConditionName);
            }
            if (null != value)
            {
                value.OnConditionDestroy(this);
            }
        }
Beispiel #9
0
        /// <summary>
        /// 状态机被销毁
        /// </summary>
        /// <param name="t_IModuleManager">状态机模块的管家</param>
        protected internal override void OnDestroy(IFSMOwner t_IFSMOwner)
        {
            //TODO:状态机被销毁后

            IsRunning = false;

            //销毁所有的状态
            IStateMapDataStructure.Foreach((key, value) => {
                value.OnStateDestroy(this);
            });
            IStateMapDataStructure.Clear();

            //销毁所有的条件
            IConditionMapDataStructure.Foreach((key, value) => {
                value.OnConditionDestroy(this);
            });
            IConditionMapDataStructure.Clear();
        }