예제 #1
0
        // State Methods

        /// <summary>
        /// Set a new state to the instance
        /// </summary>
        /// <param name="state"></param>
        public void SetState(State state)
        {
            if (!isRunning)
            {
                return;
            }

            if (state == null)
            {
                Debug.LogError("Cannot set null state");
                return;
            }

            if (m_currentState != null)
            {
                m_currentState.OnExit();
            }

            m_previousState = m_currentState;

            // Update State
            m_currentState = state;
            m_currentState.SetParent(this);
            m_currentState.OnEnter();
        }
예제 #2
0
파일: FSM.cs 프로젝트: ConnorY97/EndGame
        public void MoveTo(State state)
        {
            if (_currentState != null)
            {
                _currentState.OnExit();
            }

            _currentState       = state;
            _currentTransitions = _transitions[_currentState];

            _currentState.OnEnter();
        }
예제 #3
0
        /// <summary>
        /// State will be changed immediately.
        /// </summary>
        /// <param name="newState"></param>
        public void ChangeState(string newState)
        {
            if (m_states.ContainsKey(newState) && !string.Equals(CurrentState, newState))
            {
                m_previousState = m_currentState;
                m_previousState?.OnLeave();

                m_currentState = m_states[newState];
                m_currentState.OnEnter();
                CurrentState = newState;
                FSMHelper.Log(LogVerbose, $"State changed from {m_previousState.Name()} to {m_currentState.Name()}");
            }
        }
예제 #4
0
 private void ChangeCurrentStateAndCallOnEnter(State newState)
 {
     _currentState = newState;
     _currentState.OnEnter();
 }