Exemple #1
0
        public void ExcuteNewState(TLabel newState)
        {
            if (!_stateDic.ContainsKey(newState))
            {
                DebugMsg.LogError("状态机内不包含此状态对象:" + newState);
                return;
            }

            IFsmState <TLabel> state = _stateDic[newState];

            state.Enter();
        }
        /// <summary>
        /// Switch the state of the StateMachine
        /// </summary>
        /// <param name="state">The typeof() of the state being switched to</param>
        /// <returns>Success of the state change. Will return false if StateMachine is in the middle of a transition</returns>
        public bool ChangeState(Type state)
        {
            if (_stateLookup.ContainsKey(state) == false)
                throw new ArgumentException("Cannot change to state. Make sure it was added to StateMachine.Initialize", state.Name);

            if (IsTransitioning)
                return false;

            // When coming to change state from the started phase, go immediately to the enter phase
            _statePhase = (_statePhase == StatePhase.Started) ? StatePhase.Enter : StatePhase.Exit;
            _nextState = _stateLookup[state];
            if (_statePhase == StatePhase.Exit)
            {
                exitIterator = _currentState.Exit();
            }
            enterIterator = _nextState.Enter();

            return true;
        }
Exemple #3
0
        //执行新状态
        public void ExcuteNewState(TLabel newState)
        {
            if (!_stateDic.ContainsKey(newState))
            {
                DebugMsg.LogError("状态机内不包含此状态对象:" + newState);
                return;
            }
            _previousState = _currentState;
            _currentState  = _stateDic[newState];

            if (_previousState != null)
            {
                _previousState.Exit();
            }

            if (_currentState != null)
            {
                _currentState.Enter();
            }
        }