Exemple #1
0
        /// <summary>
        ///     Update the time the player has spent playing the given game.
        /// </summary>
        /// <param name="gameName">Name of the game which time is to be updated.</param>
        /// <param name="playedTime">Time to be saved in Player Preferences.</param>
        public static void UpdatePlayedTimeInPlayerPreferences(string gameName, float playedTime)
        {
            var playedTimePlayerPrefsKey = gameName + PlayedTimeKey;
            var savedPlayedTime          = PlayerStatisticsUtil.GetPlayedTimeFromPlayerPreferences(gameName);

            PlayerPrefs.SetFloat(playedTimePlayerPrefsKey, savedPlayedTime + playedTime);
            PlayerPrefs.Save();
        }
Exemple #2
0
        public static void UpdateGeneralHighScore(int highScore)
        {
            var totalHighScore = PlayerStatisticsUtil.GeTotaltHighScoreFromPlayerPreferences();

            if (highScore > totalHighScore)
            {
                PlayerPrefs.SetInt(PlayerStatisticsUtil.PlayerGeneralHighScoreKey, highScore);
                PlayerPrefs.Save();
            }
        }
Exemple #3
0
        /// <summary>
        ///     Updates the general score for a given game if the achieved score is higher than the saved score.
        ///     This method will be called whenever the user completes a level.
        ///     It is used so that the player can keep track of his highest score at any given level.
        /// </summary>
        /// <param name="gameName">Name of the game which level has been completed.</param>
        /// <param name="newLevelScore">Score to be updated.</param>
        private static void UpdateGeneralGameHighScoreInPlayerPreferences(string gameName, int newLevelScore)
        {
            var totalHighScorePlayerPrefsKey = gameName + HighScoreKey;
            var savedHighScore = PlayerStatisticsUtil.GetGameHighScoreFromPlayerPreferences(gameName);

            if (newLevelScore > savedHighScore)
            {
                PlayerPrefs.SetInt(totalHighScorePlayerPrefsKey, newLevelScore);
                PlayerPrefs.Save();
            }
        }
Exemple #4
0
        public void Failed()
        {
            var obj = Instantiate(FailedContainer, Default(), Identity());

            obj.transform.SetParent(GameObject.Find(Canvas).transform, true);

            obj.transform.localScale = new Vector3(20, 20, 20);

            GetPlayerStatistics();

            obj.transform.Find(Score).GetComponentInChildren <TextMesh>().text = _score.ToString();

            GameObject.Find(TotalScoreText).GetComponentInChildren <TextMesh>().text = _totalScore.ToString();

            GameObject.Find(TimerText).GetComponentInChildren <TextMesh>().text =
                PlayerStatisticsUtil.PlayedTimeToFormatedTimeSpan(TotalPlayedTime);

            ScaleControlButtons();
        }
Exemple #5
0
 private void GetPlayerStatistics()
 {
     _score      = LevelUtil.GetLevelScoreFromPlayerPreferences(GameName, _levelManager.GameLevel);
     _totalScore = PlayerStatisticsUtil.GetGameHighScoreFromPlayerPreferences(GameName);
 }
Exemple #6
0
 public void GetTotalScore()
 {
     ScoreText.text = PlayerStatisticsUtil.GeTotaltHighScoreFromPlayerPreferences().ToString(CultureInfo.InvariantCulture);
 }