//Loads game data public void LoadFromDisc() { //Create folder string saveFolder = DataSaveHandler.getMainFolder(); if (!File.Exists(saveFolder)) { Directory.CreateDirectory(saveFolder); } //Find save string filePath = DataSaveHandler.getPlayerSettingsFile(); if (File.Exists(filePath)) { //Read JSON string dataAsJson = File.ReadAllText(filePath); //Convert JSON to data object currentSettings = JsonUtility.FromJson <PlayerOptionData> (dataAsJson); } else { currentSettings = new PlayerOptionData(); defaultSettings.CopyInto(currentSettings); } }
//Saves game data public void SaveToDisc() { //Create folder string saveFolder = DataSaveHandler.getMainFolder(); if (!File.Exists(saveFolder)) { Directory.CreateDirectory(saveFolder); } //Convert to JSON string dataAsJson = JsonUtility.ToJson(currentSettings, true); //Save data File.WriteAllText(DataSaveHandler.getPlayerSettingsFile(), dataAsJson); }