/// <summary> /// As we progress through a task sequence, store the partial data value to file. /// </summary> /// <param name="seqVal">Current Sequence index value.</param> public virtual void SaveCurrentTaskSequenceValue(int seqVal) { var writer = new StreamWriter(Path.Combine(MmTaskUserData.DirPath, PartialDataFile), false, Encoding.Unicode); writer.WriteLine("Current Sequence ID," + seqVal); //TODO: Check if UserSequence is the right variable to write writer.Close(); }
public static void Save(Tile[] tiles, int score) { if (tiles != null) { try { TilesCollection TS = new TilesCollection(); TS.tsd = new TileSaveData[tiles.Length]; for (int i = 0; i < tiles.Length; i++) { TS.tsd[i] = new TileSaveData(); TS.tsd[i].i = i; TS.tsd[i].value = tiles[i].Value; } TS.score = score; HighScoreData hsd = new HighScoreData(); hsd.highScore = score > highScore ? score : highScore; string saveJSON = UnityEngine.JsonUtility.ToJson(TS, true); string highJSON = UnityEngine.JsonUtility.ToJson(hsd); if (!File.Exists(Application.persistentDataPath + "/save.json")) { File.Create(Application.persistentDataPath + "/save.json"); } if (!File.Exists(Application.persistentDataPath + "/score.json")) { File.Create(Application.persistentDataPath + "/score.json"); } StreamWriter sr; if (score > highScore) { sr = new StreamWriter(Application.persistentDataPath + "/score.json"); sr.Write(highJSON); sr.Close(); } sr = new StreamWriter(Application.persistentDataPath + "/save.json"); sr.Write(saveJSON); sr.Close(); } catch { return; } } else { try { File.Delete(Application.persistentDataPath + "/save.json"); } catch { } } }