Ejemplo n.º 1
0
    /// <summary>
    /// Changes the current state to the new state, but only if it exists in the cache.
    /// </summary>
    /// <param name="newState">The new state to use.</param>
    /// <returns>true if the new state exists in the cache and the state was changed.</returns>
    private bool ChangeState(AiStateType newStateType)
    {
        bool didStateChange = false;

        AiState newState = GetStateFromCache(newStateType);

        if (newState != null)
        {
            if (currentState != null)
            {
                currentState.OnExitState(); // give the old state a chance to cleanup
            }
            newState.OnEnterState();        // give the new state a chance to initialize
            currentState          = newState;
            this.currentStateType = newStateType;
            didStateChange        = true;
        }

        return(didStateChange);
    }