public void SaveScores(string saveFileName) { MinigameHighScoreSaveData savescores = new MinigameHighScoreSaveData(); savescores.scores = inspectorScores; string dataAsJson = JsonUtility.ToJson(savescores); string filePath = Path.Combine(Application.streamingAssetsPath, saveFileName); File.WriteAllText(filePath, dataAsJson); }
public MinigameHighscore[] GetScoresArray() { //MinigameHighscore[] scoresarray = new MinigameHighscore[numScores]; //scores.CopyTo(scoresarray, 0); //return scoresarray; SaveScores(saveFileName); MinigameHighScoreSaveData load = LoadScores(saveFileName); if (load != null) { return(load.scores); } else { return(inspectorScores); } }
public MinigameHighScoreSaveData LoadScores(string saveFileName) { MinigameHighScoreSaveData loadedData = null; string filePath = Path.Combine(Application.streamingAssetsPath, saveFileName); if (File.Exists(filePath)) { // Read the json from the file into a string string dataAsJson = File.ReadAllText(filePath); // Pass the json to JsonUtility, and tell it to create a GameData object from it loadedData = JsonUtility.FromJson <MinigameHighScoreSaveData>(dataAsJson); } else { Debug.LogError("Cannot load game data!"); } return(loadedData); }
void OnEnable() { Debug.Log("Minigame Save Data OnEnabled called."); //deserialise the scores? if (scores == null) { Debug.Log("Reinitialising scores"); MinigameHighScoreSaveData loadedScores = LoadScores(saveFileName); if (loadedScores != null) { InitScores(loadedScores.scores); } else { InitScores(null); } } }