private IEnumerator ChangeToNewStateRoutine(StateMapping i_NewState)
        {
            m_DestinationState = i_NewState;             // Chache this so that we can overwrite it and hijack a transition.

            if (m_CurrentState != null)
            {
                if (m_CurrentState.hasExitRoutine)
                {
                    m_ExitRoutine = m_CurrentState.ExitRoutine();

                    if (m_ExitRoutine != null)
                    {
                        yield return(m_StateMachineRunner.StartCoroutine(m_ExitRoutine));
                    }

                    m_ExitRoutine = null;
                }
                else
                {
                    m_CurrentState.ExitCall();
                }

                m_CurrentState.Finally();
            }

            m_PrevState    = m_CurrentState;
            m_CurrentState = m_DestinationState;

            if (m_CurrentState != null)
            {
                if (m_CurrentState.hasEnterRoutine)
                {
                    m_EnterRoutine = m_CurrentState.EnterRoutine();

                    if (m_EnterRoutine != null)
                    {
                        yield return(m_StateMachineRunner.StartCoroutine(m_EnterRoutine));
                    }

                    m_EnterRoutine = null;
                }
                else
                {
                    m_CurrentState.EnterCall();
                }

                // Broadcast change only after enter transition has begun.

                if (m_OnStateChanged != null)
                {
                    m_OnStateChanged((T)m_CurrentState.state);
                }
            }

            m_IsInTransition = false;
        }
Пример #2
0
        private IEnumerator ChangeToNewStateRoutine(StateMapping newState, StateTransition transition)
        {
            destinationState = newState;             //Chache this so that we can overwrite it and hijack a transition

            if (currentState != null)
            {
                if (currentState.hasExitRoutine)
                {
                    exitRoutine = currentState.ExitRoutine();

                    if (exitRoutine != null && transition != StateTransition.Overwrite)                     //Don't wait for exit if we are overwriting
                    {
                        yield return(engine.StartCoroutine(exitRoutine));
                    }

                    exitRoutine = null;
                }
                else
                {
                    currentState.ExitCall();
                }

                currentState.Finally();
            }

            lastState    = currentState;
            currentState = destinationState;

            if (currentState != null)
            {
                if (currentState.hasEnterRoutine)
                {
                    enterRoutine = currentState.EnterRoutine();

                    if (enterRoutine != null)
                    {
                        yield return(engine.StartCoroutine(enterRoutine));
                    }

                    enterRoutine = null;
                }
                else
                {
                    currentState.EnterCall();
                }

                //Broadcast change only after enter transition has begun.
                if (Changed != null)
                {
                    Changed((T)currentState.state);
                }
            }

            isInTransition = false;
        }