Ejemplo n.º 1
0
    void SetState(EGameState state, bool force = false)
    {
        if (state == currentState && !force)
        {
            return;
        }
        stateTime = 0f;
        EGameState fromState = currentState;

        currentState = state;
        if (stateFunctions.ContainsKey(currentState))
        {
            currentStateFunctions = stateFunctions[currentState];
        }
        else
        {
            currentStateFunctions = null;
        }
        currentStateTransition = null;
        GameEvents.OnGameStateEntered(currentState, fromState);
        //GameEvents.OnGameStateChange(fromState, currentState);
    }
Ejemplo n.º 2
0
    void TransitionToState(EGameState state)
    {
        GameEvents.OnGameStateExit(currentState, state);
        bool foundTransition = false;
        Dictionary <EGameState, GameStateTransitionBase> toTransitions;

        if (stateTransitions.TryGetValue(currentState, out toTransitions))
        {
            GameStateTransitionBase transition;
            if (toTransitions.TryGetValue(state, out transition))
            {
                currentStateTransition = transition;
                currentStateTransition.StartTransition(this);
                foundTransition = true;
            }
        }

        if (!foundTransition)
        {
            SetState(state);
        }
    }