private void SetStatusString() { Status status = cardManager.GetGameStatus(PlayerWeapon, ComputerWeapon); AddToTheTotalPlayerPrefCount(PlayerPrefKeys.PlayerWeaponKey(PlayerWeapon.weapon)); AddToTheTotalPlayerPrefCount(PlayerPrefKeys.ComputerWeaponKey(ComputerWeapon.weapon)); if (status == Status.Win) { wins++; AddToTheTotalPlayerPrefCount(PlayerPrefKeys.TOTALWINS); StatusText.text = "You Win!"; } else if (status == Status.Lose) { loses++; AddToTheTotalPlayerPrefCount(PlayerPrefKeys.TOTALLOSES); StatusText.text = "You Lost!"; } else { ties++; AddToTheTotalPlayerPrefCount(PlayerPrefKeys.TOTALTIES); StatusText.text = "Tie Game!"; } }
/// <summary> /// Checks to see if the game was won and the current move count is less than the recorded best for the current difficulty. /// If so, saves it and indicates in game that it is new. /// </summary> private void SetLeastMoves() { string leastMovesKey = PlayerPrefKeys.GetLeastMovesKey(Config.config.currentDifficulty); if (Config.config.gameWin) { int currentMoves = Config.config.moveCounter; if (!PlayerPrefs.HasKey(leastMovesKey) || currentMoves < PlayerPrefs.GetInt(leastMovesKey)) { PlayerPrefs.SetInt(leastMovesKey, currentMoves); leastMoves.color = Color.cyan; leastMovesStat.color = Color.cyan; leastMovesStat.text = currentMoves.ToString(); } else { leastMovesStat.text = PlayerPrefs.GetInt(leastMovesKey).ToString(); } } else if (PlayerPrefs.HasKey(leastMovesKey)) { leastMovesStat.text = PlayerPrefs.GetInt(leastMovesKey).ToString(); } else { leastMovesStat.text = "NULL"; } }
private void Awake() { if (config == null) { DontDestroyOnLoad(gameObject); //makes instance persist across scenes config = this; } else if (config != this) { Destroy(gameObject); //deletes copies of global which do not need to exist, so right version is used to get info from } PlayerPrefKeys.CheckKeys(); }
public void ClearRecordsConfirmationButton(bool confirm) { if (confirm) { // since ResultsScript.cs detects and auto fills the very first records this is how it must be done foreach (string difficulty in Config.config.difficulties) { PlayerPrefs.DeleteKey(PlayerPrefKeys.GetHighScoreKey(difficulty)); PlayerPrefs.DeleteKey(PlayerPrefKeys.GetLeastMovesKey(difficulty)); } } confirmButton.SetActive(false); }
/// <summary> /// Checks to see if the current score is better than the recorded best for the current difficulty. /// If so, saves it and indicates in game that it is new. /// </summary> private void SetHighScore() { string highScoreKey = PlayerPrefKeys.GetHighScoreKey(Config.config.currentDifficulty); int currentScore = Config.config.score; if (!PlayerPrefs.HasKey(highScoreKey) || currentScore > PlayerPrefs.GetInt(highScoreKey)) { PlayerPrefs.SetInt(highScoreKey, currentScore); highScore.color = Color.cyan; highScoreStat.color = Color.cyan; highScoreStat.text = currentScore.ToString(); } else { highScoreStat.text = PlayerPrefs.GetInt(highScoreKey).ToString(); } }
// Start is called before the first frame update void Start() { lockout = true; PlayerPrefKeys.CheckKeys(); // music volume int volume = (int)(PlayerPrefs.GetFloat(PlayerPrefKeys.musicVolumeKey) * 10); musicSlider.GetComponent <Slider>().value = volume; musicVolumeText.text = (volume * 10).ToString() + '%'; // sound effects volume volume = (int)(PlayerPrefs.GetFloat(PlayerPrefKeys.soundEffectsVolumeKey) * 10); soundEffectsSlider.GetComponent <Slider>().value = volume; soundEffectsVolumeText.text = (volume * 10).ToString() + '%'; bool isOn; // vibration enabled if (System.Boolean.TryParse(PlayerPrefs.GetString(PlayerPrefKeys.vibrationEnabledKey), out isOn)) { vibrationToggle.GetComponent <Toggle>().isOn = isOn; } else { // unable to parse vibrationToggle.GetComponent <Toggle>().isOn = false; } // food suits enabled if (System.Boolean.TryParse(PlayerPrefs.GetString(PlayerPrefKeys.foodSuitsEnabledKey), out isOn)) { foodSuitsToggle.GetComponent <Toggle>().isOn = isOn; } else { // unable to parse foodSuitsToggle.GetComponent <Toggle>().isOn = false; } lockout = false; }
// Setup for the setup tab private async void SetupTheSetupData() { // Create an empty setup CacheManager.SetupTab.Setup = new SetupMVC(GameObject.Find("SetupPanel").GetComponent <SetupView>()); // Check if a username is stored and set+load from that if so if (PlayerPrefs.HasKey(PlayerPrefKeys.GetKeyName(PlayerPrefKeys.KeyNamesEnum.Username))) { await CacheManager.SetupTab.Setup.LoadNewPlayerStatsAsync(PlayerPrefs.GetString(PlayerPrefKeys.GetKeyName(PlayerPrefKeys.KeyNamesEnum.Username))); } // Load saved setups from file setupDictionary.Load(); // Trigger events for after all initial required data has been loaded EventManager.Instance.DataLoaded(); // Trigger end of UI loading to give user control EventManager.Instance.UILoaded(); setupDictionary.HasUnsavedData = false; }
// Use this for initialization void UpdateScores() { sessionWins.text = GetIfAvailable(PlayerPrefKeys.SESSIONWINS).ToString(); sessionLoses.text = GetIfAvailable(PlayerPrefKeys.SESSIONLOSES).ToString(); sessionTies.text = GetIfAvailable(PlayerPrefKeys.SESSIONTIES).ToString(); totalWins.text = GetIfAvailable(PlayerPrefKeys.TOTALWINS).ToString(); totalLoses.text = GetIfAvailable(PlayerPrefKeys.TOTALLOSES).ToString(); totalTies.text = GetIfAvailable(PlayerPrefKeys.TOTALTIES).ToString(); WeaponData topUserWeaponData = null; foreach (WeaponData weapon in CardManager.GetInstance().weapons) { if (topUserWeaponData == null) { topUserWeaponData = weapon; continue; } int maxWeaponCount = GetIfAvailable(PlayerPrefKeys.PlayerWeaponKey(topUserWeaponData.weapon)); int currentWeaponCount = GetIfAvailable(PlayerPrefKeys.PlayerWeaponKey(weapon.weapon)); if (currentWeaponCount > maxWeaponCount) { topUserWeaponData = weapon; } } if (GetIfAvailable(PlayerPrefKeys.PlayerWeaponKey(topUserWeaponData.weapon)) > 0) { topUserWeapon.text = topUserWeaponData.weapon + " (" + GetIfAvailable(PlayerPrefKeys.PlayerWeaponKey(topUserWeaponData.weapon)) + ")"; } else { topUserWeapon.text = "N/A"; } WeaponData topComputerWeaponData = null; foreach (WeaponData weapon in CardManager.GetInstance().weapons) { if (topComputerWeaponData == null) { topComputerWeaponData = weapon; continue; } int maxWeaponCount = GetIfAvailable(PlayerPrefKeys.ComputerWeaponKey(topComputerWeaponData.weapon)); int currentWeaponCount = GetIfAvailable(PlayerPrefKeys.ComputerWeaponKey(weapon.weapon)); if (currentWeaponCount > maxWeaponCount) { topComputerWeaponData = weapon; } } if (GetIfAvailable(PlayerPrefKeys.ComputerWeaponKey(topComputerWeaponData.weapon)) > 0) { topComputerWeapon.text = topComputerWeaponData.weapon + " (" + GetIfAvailable(PlayerPrefKeys.ComputerWeaponKey(topComputerWeaponData.weapon)) + ")"; } else { topComputerWeapon.text = "N/A"; } }
private void NewUsernameEntered() { EventManager.Instance.NewUsernameEntered(thisIF.text); PlayerPrefs.SetString(PlayerPrefKeys.GetKeyName(PlayerPrefKeys.KeyNamesEnum.Username), thisIF.text); PlayerPrefs.Save(); }