コード例 #1
0
 /// <summary>
 /// Registers the state.
 /// </summary>
 /// <param name="state">State.</param>
 public void RegisterState(FSMstate state)
 {
     if (state == null)
     {
         Debug.LogError("FSM 注册失败,state为null");
         return;
     }
     stateMap[state.GetStateId()] = state;
 }
コード例 #2
0
        /// <summary>
        /// Switchs the state.
        /// </summary>
        /// <returns><c>true</c>, if state was switched, <c>false</c> otherwise.</returns>
        /// <param name="stateId">State identifier.</param>
        /// <param name="enterParamMap">Enter parameter map, can be null</param>
        public bool SwitchState(Enum stateId, Dictionary <string, object> enterParamMap)
        {
            if (!stateMap.ContainsKey(stateId))
            {
                Debug.LogError("FSM 切换失败,未注册的状态 : " + stateId);
                return(false);
            }
            if (mState != null)
            {
                if (mState.GetStateId() == stateId)
                {
                    Debug.Log("FSM 状态无需改变");
                    return(true);
                }
                mState.OnLeaveState();
            }
            mState = stateMap[stateId];
            mState.OnEnterState(enterParamMap);

            return(true);
        }