public void LoadSettingsFromSavedData(StandaloneSavedData sData) { if (sData == null) { // new game data ResetSettings(); Debug.Log("SETTINGS: Error loading StandaloneSavedData, creating new settings."); } else { SettingsVersion = sData.SettingsVersion; Users = sData.Users; ChangeUser(sData.CurrentUser); User.Name = sData.CurrentUser; User.AvatarId = sData.AvatarId; User.CurrentLevelNumber = sData.CurrentLevelNumber; User.LevelsCompleted = sData.LevelsCompleted; // options User.MusicVolume = sData.MusicVolume; User.SoundVolume = sData.SoundVolume; User.LastTrack = sData.LastTrack; User.DontShowExitGameWindow = sData.DontShowExitGameWindow; User.Alarms = sData.Alarms; Debug.Log("SETTINGS: Loaded successfully."); } sData = null; }
/// <summary> /// Loads user data from Unity's PlayerPrefs /// </summary> public void Load() { Debug.Log("SETTINGS: Start Loading"); if (PlayerPrefs.HasKey(Consts.APP_SHORTNAME)) { Debug.Log("SETTINGS: Loading from local device..."); string rawStringBinaryData = PlayerPrefs.GetString(Consts.APP_SHORTNAME); StandaloneSavedData standaloneSavedData = null; try { string decompressedJSON = GZipHelper.Decompress(rawStringBinaryData); standaloneSavedData = JsonUtility.FromJson <StandaloneSavedData>(decompressedJSON); } catch (Exception ex) { Debug.Log("SETTING: Error parsing local saved settings object.\n" + ex.Message); } LoadSettingsFromSavedData(standaloneSavedData); } else { Debug.Log("SETTINGS: No saved settings found. Creating new settings."); ResetSettings(); Save(); Load(); } }
/// <summary> /// Saves user data to Unity's PlayerPrefs /// </summary> public void Save(bool isExitSave = false) { StandaloneSavedData sData = new StandaloneSavedData(); sData.SettingsVersion = SettingsVersion; sData.Users = Users; sData.CurrentUser = User.Name; sData.AvatarId = User.AvatarId; sData.CurrentLevelNumber = User.CurrentLevelNumber; sData.LevelsCompleted = User.LevelsCompleted; // options sData.MusicVolume = User.MusicVolume; sData.SoundVolume = User.SoundVolume; sData.LastTrack = User.LastTrack; sData.DontShowExitGameWindow = User.DontShowExitGameWindow; sData.Alarms = User.Alarms; string json = GZipHelper.Compress(JsonUtility.ToJson(sData)); PlayerPrefs.SetString(Consts.APP_SHORTNAME, json); Debug.Log("SETTINGS: Saving to local device."); PlayerPrefs.SetInt("SettingsVersion", SettingsVersion); PlayerPrefs.Save(); }
public void LoadSettingsFromSavedData(StandaloneSavedData sData) { if (sData == null) { // new game data ResetSettings(); //FINAL Debug.Log("SETTINGS: Error loading StandaloneSavedData, creating new settings."); } else { if (sData.SettingsVersion != Consts.APP_VERSION) { ResetSettings(); } else { if (sData.SettingsVersion > Consts.APP_VERSION) { Debug.LogError("New version avialable. Please update the application."); //TODO: Application.Quit(); } while (sData.SettingsVersion < Consts.APP_VERSION) // update to actual version { UpgradeSavedData(ref sData); } User = sData.User; ApplyUser(); //FINAL Debug.Log("SETTINGS: Loaded successfully."); } } }
void UpgradeSavedData(ref StandaloneSavedData data) { //TODO: Зробити апгрейд данних, якщо треба //if (data.SettingsVersion < 82) //{ // Debug.Log("XX->82"); // data.SettingsVersion = 82; //} }
/// <summary> /// Saves user data to Unity's PlayerPrefs /// </summary> public void Save(bool isExitSave = false) { StandaloneSavedData sData = new StandaloneSavedData(); sData.User = User; sData.SettingsVersion = Consts.APP_VERSION; string json = GZipHelper.Compress(JsonUtility.ToJson(sData)); PlayerPrefs.SetString(Consts.PROJECT_NAME, json); //FINAL Debug.Log("SETTINGS: Saving to local device."); PlayerPrefs.SetInt("SettingsVersion", Consts.APP_VERSION); //SettingsVersion); PlayerPrefs.Save(); }