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); }
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); } }