/// <summary> /// Shows the pause window dialog. /// </summary> /// Override this in your own base class if you want to customise the settings window. Be sure to call this base instance when done. public virtual void Show() { GameObjectHelper.SafeSetActive(GameObjectHelper.GetChildNamedGameObject(DialogInstance.gameObject, "Restart", true), ShowRestart); GameObjectHelper.SafeSetActive(GameObjectHelper.GetChildNamedGameObject(DialogInstance.gameObject, "Options", true), ShowOptions); GameObjectHelper.SafeSetActive(GameObjectHelper.GetChildNamedGameObject(DialogInstance.gameObject, "ExitLevel", true), ShowExitLevel); GameObjectHelper.SafeSetActive(GameObjectHelper.GetChildNamedGameObject(DialogInstance.gameObject, "Quit", true), ShowQuit); // show the dialog DialogInstance.Show(destroyOnClose: false); }
/// <summary> /// Shows the settings dialog. /// </summary> /// Override this in your own base class if you want to customise the settings window. Be sure to call this base instance when done. public virtual void Show() { // save any values in case of cancel _oldBackGroundAudioVolume = GameManager.Instance.BackGroundAudioVolume; // set values in UI _musicVolume.value = GameManager.Instance.BackGroundAudioVolume; _sfxVolume.value = GameManager.Instance.EffectAudioVolume; _language.options = (from item in LocaliseText.AllowedLanguages select new Dropdown.OptionData(LocaliseText.Get("Language.LocalisedName", item))).ToList(); for (var i = 0; i < LocaliseText.AllowedLanguages.Length; i++) { if (LocaliseText.AllowedLanguages[i] == LocaliseText.Language) { _language.value = i; } } // show the dialog DialogInstance.Show(doneCallback: DoneCallback, destroyOnClose: false); }
/// <summary> /// Callback when the dialog is ready to close /// </summary> public void DoneFinished() { if (DoneCallback != null) { DoneCallback(this); } Target.SetActive(false); if (_destroyOnClose) { Destroy(gameObject); } // decrease open count - not thread safe, but should be ok! DialogManager.Instance.Count--; IsShown = false; if (_swapToDialogInstance != null) { _swapToDialogInstance.Show(destroyOnClose: false); _swapToDialogInstance = null; } }
/// <summary> /// Shows the game over dialog. /// </summary> /// Override this in your own base class if you want to customise the game over window. Be sure to call this base instance when done. public virtual void Show(bool isWon) { Assert.IsTrue(LevelManager.IsActive, "Ensure that you have a LevelManager component attached to your scene."); var currentLevel = GameManager.Instance.Levels.Selected; // update the player score if necessary if ((UpdatePlayerScore == CopyType.Always) || (UpdatePlayerScore == CopyType.OnWin && isWon)) { GameManager.Instance.Player.AddPoints(currentLevel.Score); } // update the player coins if necessary if ((UpdatePlayerCoins == CopyType.Always) || (UpdatePlayerCoins == CopyType.OnWin && isWon)) { GameManager.Instance.Player.AddCoins(currentLevel.Coins); } // show won / lost game objects as appropriate GameObjectHelper.SafeSetActive(GameObjectHelper.GetChildNamedGameObject(DialogInstance.gameObject, "Lost", true), !isWon); // see if the world or game is won and also if we should unlock the next world / level GameObjectHelper.SafeSetActive(GameObjectHelper.GetChildNamedGameObject(DialogInstance.gameObject, "GameWon", true), false); GameObjectHelper.SafeSetActive(GameObjectHelper.GetChildNamedGameObject(DialogInstance.gameObject, "WorldWon", true), false); GameObjectHelper.SafeSetActive(GameObjectHelper.GetChildNamedGameObject(DialogInstance.gameObject, "LevelWon", true), false); GameObjectHelper.SafeSetActive(GameObjectHelper.GetChildNamedGameObject(DialogInstance.gameObject, "Won", true), false); if (isWon) { //TODO: if coins unlock mode then need to check all levels are done before saying world complete - same for game... //TODO: perhaps in future we might want to distinguish between the first and subsequent times a user completes something? //// is the game won //if (GameHelper.IsCurrentLevelLastInGame()) { // GameObjectHelper.SafeSetActive(GameObjectHelper.GetChildNamedGameObject(DialogInstance.gameObject, "GameWon", true), true); //} //// is a world won //else if (GameHelper.IsCurrentLevelLastInGame()) //{ // GameObjectHelper.SafeSetActive(GameObjectHelper.GetChildNamedGameObject(DialogInstance.gameObject, "WorldWon", true), true); //} //// level won //else if (GameManager.Instance.Levels.GetNextItem() != null) //{ // GameObjectHelper.SafeSetActive(GameObjectHelper.GetChildNamedGameObject(DialogInstance.gameObject, "LevelWon", true), true); //} //// else won with some other condition //else //{ GameObjectHelper.SafeSetActive(GameObjectHelper.GetChildNamedGameObject(DialogInstance.gameObject, "Won", true), true); //} // process and update game state - do this last so we can check some bits above. GameHelper.ProcessCurrentLevelComplete(); } // set some text based upon the result UIHelper.SetTextOnChildGameObject(DialogInstance.gameObject, "AchievementText", LocaliseText.Format(LocalisationBase + ".Achievement", currentLevel.Score, currentLevel.Name)); // setup stars var starsGameObject = GameObjectHelper.GetChildNamedGameObject(DialogInstance.gameObject, "Stars", true); GameObjectHelper.SafeSetActive(starsGameObject, ShowStars); if (ShowStars) { Assert.IsNotNull(starsGameObject, "GameOver->ShowStars is enabled, but could not find a 'Stars' gameobject. Disable the option or fix the structure."); starsGameObject.SetActive(ShowStars); var newStarsWon = GetNewStarsWon(); currentLevel.StarsWon |= newStarsWon; var star1WonGameObject = GameObjectHelper.GetChildNamedGameObject(starsGameObject, "Star1", true); var star2WonGameObject = GameObjectHelper.GetChildNamedGameObject(starsGameObject, "Star2", true); var star3WonGameObject = GameObjectHelper.GetChildNamedGameObject(starsGameObject, "Star3", true); StarWon(currentLevel.StarsWon, newStarsWon, star1WonGameObject, 1); StarWon(currentLevel.StarsWon, newStarsWon, star2WonGameObject, 2); StarWon(currentLevel.StarsWon, newStarsWon, star3WonGameObject, 4); GameObjectHelper.SafeSetActive(GameObjectHelper.GetChildNamedGameObject(starsGameObject, "StarWon", true), newStarsWon != 0); } // set time var difference = DateTime.Now - LevelManager.Instance.StartTime; var timeGameObject = GameObjectHelper.GetChildNamedGameObject(DialogInstance.gameObject, "Time", true); GameObjectHelper.SafeSetActive(timeGameObject, ShowTime); if (ShowTime) { Assert.IsNotNull(timeGameObject, "GameOver->ShowTime is enabled, but could not find a 'Time' gameobject. Disable the option or fix the structure."); UIHelper.SetTextOnChildGameObject(timeGameObject, "TimeResult", difference.Minutes.ToString("D2") + "." + difference.Seconds.ToString("D2"), true); } // set coins var coinsGameObject = GameObjectHelper.GetChildNamedGameObject(DialogInstance.gameObject, "Coins", true); GameObjectHelper.SafeSetActive(coinsGameObject, ShowCoins); if (ShowCoins) { Assert.IsNotNull(coinsGameObject, "GameOver->ShowCoins is enabled, but could not find a 'Coins' gameobject. Disable the option or fix the structure."); UIHelper.SetTextOnChildGameObject(coinsGameObject, "CoinsResult", currentLevel.Coins.ToString(), true); } // set score var scoreGameObject = GameObjectHelper.GetChildNamedGameObject(DialogInstance.gameObject, "Score", true); GameObjectHelper.SafeSetActive(scoreGameObject, ShowScore); if (ShowScore) { Assert.IsNotNull(scoreGameObject, "GameOver->ShowScore is enabled, but could not find a 'Score' gameobject. Disable the option or fix the structure."); var distanceText = LocaliseText.Format(LocalisationBase + ".ScoreResult", currentLevel.Score.ToString()); if (currentLevel.HighScore > currentLevel.OldHighScore) { distanceText += "\n" + LocaliseText.Get(LocalisationBase + ".NewHighScore"); } UIHelper.SetTextOnChildGameObject(scoreGameObject, "ScoreResult", distanceText, true); } UpdateNeededCoins(); // save game state. GameManager.Instance.Player.UpdatePlayerPrefs(); currentLevel.UpdatePlayerPrefs(); PreferencesFactory.Save(); //show dialog DialogInstance.Show(); //TODO bug - as we increase TimesPlayedForRatingPrompt on both game start (GameManager) and level finish we can miss this comparison. if (GameManager.Instance.TimesPlayedForRatingPrompt == TimesPlayedBeforeRatingPrompt) { var gameFeedback = new GameFeedback(); gameFeedback.GameFeedbackAssumeTheyLikeOptional(); } #if UNITY_ANALYTICS // record some analytics on the level played var values = new Dictionary <string, object> { { "score", currentLevel.Score }, { "Coins", currentLevel.Coins }, { "time", difference }, { "level", currentLevel.Number } }; Analytics.CustomEvent("GameOver", values); #endif // co routine to periodic updates of display (don't need to do this every frame) if (!Mathf.Approximately(PeriodicUpdateDelay, 0)) { StartCoroutine(PeriodicUpdate()); } }