/// <summary> /// Called from a Unity button, uploads the highscore to Firebase. /// </summary> public void Upload(InputField usernameInputField) { Text placeholderText = usernameInputField.placeholder.GetComponent <Text>(); string formatted = Utilities.StripNonLatinLetters(usernameInputField.text); if (highscoreManager.GetLocalHighscore() <= 0) { placeholderText.text = Constants.SCORE_NOT_ZERO; } else if (string.IsNullOrEmpty(usernameInputField.text)) { placeholderText.text = Constants.NICKNAME_REQUIRED; } else if (PlayerPrefs.GetInt(Constants.ALREADY_UPLOADED_KEY) != 0) { usernameInputField.text = ""; placeholderText.text = Constants.ALREADY_UPLOADED; } else if (string.IsNullOrEmpty(formatted)) { usernameInputField.text = ""; placeholderText.text = Constants.INVALID_NAME; } else { highscoreManager.UploadNewHighscore(formatted, highscoreManager.GetLocalHighscore()); usernameInputField.text = ""; placeholderText.text = Constants.UPLOADED; } }
public IEnumerator ShouldSaveNewHighscore() { PlayerPrefs.SetInt(PlayerPrefKeys.HIGHSCORE, 50); hm.SaveLocalHighscore(100); yield return(new WaitForSeconds(TestConstants.WAIT_TIME)); Assert.AreEqual(100, hm.GetLocalHighscore()); }
public IEnumerator SaveWorksIfNewHighscoreAchieved() { // Set a score first PlayerPrefs.SetInt(Constants.PLAYER_PREFS_HIGHSCORE_KEY, 50); manager.SaveLocalHighscore(100); Assert.AreEqual(100, manager.GetLocalHighscore()); Assert.AreEqual(0, PlayerPrefs.GetInt(Constants.ALREADY_UPLOADED_KEY)); // Also check that uploaded is set to no (0) yield return(new WaitForSeconds(WAIT_TIME)); }
private void Start() { highscoreManager = HighscoreManager.instance; localHighscoreText.text = highscoreManager.GetLocalHighscore().ToString(); statusText.text = "Downloading highscores..."; statusText.color = Color.green; if (Utilities.isOctober()) { halloweenUi.SetActive(true); normalParticleSystem.SetActive(false); } if (Utilities.isDecember()) { christmasUi.SetActive(true); normalParticleSystem.SetActive(false); } InvokeRepeating("RefreshHighscores", 0f, refreshRate); }
/// <summary> /// Routine called when a Ghost collides with Pacman. /// </summary> private IEnumerator Die() { debugger.Info("has died"); currentLives--; audioManager.PauseAllSounds(); goManager.StopMovingEntities(); audioManager.Pause(SoundNames.GHOST_MOVE); audioManager.GetSound(SoundNames.GHOST_MOVE).source.pitch = Constants.GHOST_MOVE_PITCH; yield return(new WaitForSeconds(1f)); audioManager.Play(SoundNames.PACMAN_DEATH); yield return(new WaitForSeconds(audioManager.GetSound(SoundNames.PACMAN_DEATH).clip.length + 1f)); goManager.ResetEntityPositions(); if (currentLives < 0) { bool newHighscore = false; int score = pacmanScore.GetScore(); HighscoreManager highscoreManager = HighscoreManager.instance; if (score > highscoreManager.GetLocalHighscore()) { highscoreManager.SaveLocalHighscore(score); newHighscore = true; } gameEventManager.GameOver(newHighscore); } else { pacmanHud.RemoveLife(currentLives); gameEventManager.RespawnPacman(); audioManager.Play(SoundNames.GHOST_MOVE); } }