public FMCGameInstance() { gameProperties = new Dictionary <string, object>(); GameState = FMCGameState.SplashScreen; #if UNITY_EDITOR if (SceneManager.GetActiveScene().name != "FMCSplashScreen") { //FMCGameInstance should be created inside the first scene (Splash screen) //If we are already in the game scene, it means that we started inside the scene in the editor. //Let's simulate the state change event to make the transition consistent GoToState(FMCGameState.TitleScreen); } #endif }
void UpdateUIFromState(FMCGameState state) { switch (state) { case FMCGameState.TitleScreen: titleScreenBestScoreLabel.text = fmc.game.BestScore.ToString(); break; case FMCGameState.Playing: gameBestScoreLabel.text = fmc.game.BestScore.ToString(); newBestScoreLabel.gameObject.SetActive(false); if (!fmc.utils.IsNullOrWhiteSpace(tutorialLabel.text) && !hasLost) { tutorialLabel.gameObject.SetActive(true); tutorialLabel.alpha = 1; TweenAlpha.Begin(tutorialLabel.gameObject, 1, 0, 2); } break; case FMCGameState.GameOver: gameOverSecondChanceUI.gameObject.SetActive(false); gameOverNormalUI.gameObject.SetActive(true); if (!hasLost) { gameOverAdsButton.ShowAdsButton(adsButtonDuration); } else { fmc.ads.ShowInterstitial(); //Showing interstitial only on second run game over fmc.ads.ShowBanner(); //updating banner on second run game over } hasLost = true; gameOverTime = Time.time; gameOverBestScoreLabel.text = fmc.game.BestScore.ToString(); gameOverScoreLabel.text = fmc.game.CurrentScore.ToString(); break; } allScreenButton.gameObject.SetActive(state == FMCGameState.GameOver); TweenAlpha.Begin(titleSreenUI.gameObject, UITransitionsDuration, state == FMCGameState.TitleScreen ? 1 : 0); TweenAlpha.Begin(gameUI.gameObject, UITransitionsDuration, state == FMCGameState.Playing ? 1 : 0); TweenAlpha.Begin(gameOverUI.gameObject, UITransitionsDuration, state == FMCGameState.GameOver ? 1 : 0); }
/// <summary> /// Updates the state machine of the GameInstance and fires the appropriate events /// </summary> public void GoToState(FMCGameState newState) { if (newState == FMCGameState.GameOver) { if (fmc.game.Settings.enableLevelSystem && fmc.game.Level < fmc.game.Settings.maxLevels) { int pointsGained; if (fmc.game.Settings.quickLevelUp) {//always finish the level pointsGained = fmc.game.Settings.levelDuration.GetValue(fmc.game.Level) - fmc.game.Experience + 10; } else {//normal behavior pointsGained = fmc.game.CurrentScore; if (!gameWasReset) { pointsGained -= lastScore; //player will only get difference if it had a second chance } lastScore = fmc.game.CurrentScore; } if (GainingExperienceAction != null) { GainingExperienceAction.Invoke(pointsGained); } GainExperience(pointsGained); } if (GameOverAction != null) { GameOverAction.Invoke(fmc.game.CurrentScore); } } else if (newState == FMCGameState.Playing) { if (GameState == FMCGameState.GameOver && !gameWasReset) { if (ResumedFromGameOverAction != null) { ResumedFromGameOverAction.Invoke(); } } if (GameStartedAction != null) { GameStartedAction.Invoke(); } gameWasReset = false; } else if (newState == FMCGameState.TitleScreen) { if (GoingToTitleScreenAction != null) { GoingToTitleScreenAction.Invoke(); } } if (GameStateChanged != null) { GameStateChanged.Invoke(GameState, newState); } GameState = newState; }