Esempio n. 1
0
        /// <summary>
        /// Switch to another state.
        /// State to be activated must be added first using AddGameState()
        /// When this is called
        ///     - current state goes first from Running status to Exiting and finally to Hidden.
        ///     - nextState goes from Hidden status to Entering and finally Running.
        /// How long this takes, is controlled by each states' EnterStateInterval and ExitStateInterval
        /// </summary>
        /// <param name="nextState">The state to be activated</param>
        public void SwitchToState(GameState nextState)
        {
            if (PauseState != null && PauseState.IsActive)
            {
                PauseState.ExitState();
            }

            if (nextState != CurrentState && gameStates.Contains(nextState))
            {
                nextState.LoadContent();
                PreviousState = CurrentState;
                // switch to next state
                if (CurrentState != null)
                {
                    CurrentState.ExitState();
                }
                nextState.EnterState();
                if (nextState.IsSlowLoadingState)
                {
                    // TODO: Should bump up a loading state of some kind
                }
                ExitingState = CurrentState;
                CurrentState = nextState;
            }
        }
Esempio n. 2
0
 /// <summary>
 /// Unpause the current state, PauseState will become inactive
 /// </summary>
 public void UnPauseCurrentState()
 {
     if (PauseState != null)
     {
         PauseState.ExitState();
     }
     CurrentState.UnPause();
 }
    public void SwitchState()
    {
        GameObject.FindGameObjectWithTag("Player").GetComponent <WeaponScript>().AddAmmo();

        if (currentState == gameplayState)
        {
            gameplayState.ExitState();
            pauseState.EnterState();
            currentState = pauseState;
        }
        else if (currentState == pauseState)
        {
            pauseState.ExitState();
            gameplayState.EnterState();
            currentState = gameplayState;
        }
    }