Ejemplo n.º 1
0
        /// <summary>
        /// 改变状态
        /// </summary>
        public void ChangeState(int stateType)
        {
            MoFsmState state = GetState(stateType);

            if (state == null)
            {
                MoLog.Log(ELogType.Error, "Can not found state {0}", stateType);
                return;
            }

            //全局状态不需要检测
            if (_runState.Type != _globalState.Type && state.Type != _globalState.Type)
            {
                if (_runState.CanChangeTo(stateType) == false)
                {
                    MoLog.Log(ELogType.Error, "Can not change state {0} to {1}", _runState, state);
                    return;
                }
            }

            MoLog.Log(ELogType.Log, "Change state {0} to {1}", _runState, state);
            _preState = _runState;
            _runState.Exit();
            _runState = state;
            _runState.Enter();
        }
Ejemplo n.º 2
0
 public void Run(int runStateType, int globalStateType)
 {
     _runState    = GetState(runStateType);
     _preState    = GetState(runStateType);
     _globalState = GetState(globalStateType);
     _runState.Enter();
 }
Ejemplo n.º 3
0
        /// <summary>
        /// 添加一个状态
        /// </summary>
        public void AddState(MoFsmState state)
        {
            if (state == null)
            {
                throw new ArgumentNullException();
            }

            if (_states.Contains(state) == false)
            {
                _states.Add(state);
            }
        }