Ejemplo n.º 1
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;
    }
Ejemplo n.º 2
0
    private IEnumerator ChangeToNewStateRoutine(StateMapping newState, StateTransition transtiion)
    {
        _destinationState = newState;

        if (_currentState != null)
        {
            if (_currentState.hasExitRoutine)
            {
                _exitRoutine = _currentState.ExitRoutine();

                if (_exitRoutine != null && transtiion != StateTransition.Overwrite)
                {
                    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();
            }

            if (Changed != null)
            {
                Changed(_currentState.State);
            }
        }

        _isInTransition = false;
    }