예제 #1
0
        public DialogInstance Show(string prefab = null, string title = null, string titleKey = null, string text = null, string textKey = null, string text2 = null, string text2Key = null, Sprite sprite = null, System.Action <DialogInstance> doneCallback = null, DialogInstance.DialogButtonsType dialogButtons = DialogInstance.DialogButtonsType.Ok)
        {
            DialogInstance generalMessage = Create(prefab);

            generalMessage.Show(title, titleKey, text, textKey, text2, text2Key, sprite, doneCallback, dialogButtons: dialogButtons);
            return(generalMessage);
        }
예제 #2
0
        public virtual void Show()
        {
            // set values
            _oldBackGroundAudioVolume = GameManager.Instance.BackGroundAudioVolume;
            _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;
                }
            }

            DialogInstance.Show(doneCallback: DoneCallback, destroyOnClose: false);
        }
예제 #3
0
        public void DoneFinished()
        {
            if (DoneCallback != null)
            {
                DoneCallback(this);
            }

            DialogGameObject.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;
            }
        }
예제 #4
0
        public virtual void Show(bool isWon)
        {
            Assert.IsTrue(LevelManager.IsActive, "Ensure that you have a LevelManager component attached to your scene.");

            Level currentLevel = GameManager.Instance.Levels.Selected;

            // 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
            TimeSpan 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();
            PlayerPrefs.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)
            {
                GameFeedback 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());
            }
        }