public void LoadData(System.Action <GameSaveData> OnLoadCompleted) { CreateDirectoryIfNeeded(); string fileContents = null; if (File.Exists(fullPath)) { fileContents = File.ReadAllText(fullPath); } GameSaveData saveData; if (!string.IsNullOrEmpty(fileContents)) { saveData = JsonUtility.FromJson <GameSaveData>(fileContents); } else { saveData = new GameSaveData() { Value = "" } }; OnLoadCompleted?.Invoke(saveData); }
public void SaveData(GameSaveData saveData) { CreateDirectoryIfNeeded(); string fileContents = JsonUtility.ToJson(saveData); File.WriteAllText(fullPath, fileContents); }