public static void SaveData() { BinaryFormatter formatter = new BinaryFormatter(); string path = Application.persistentDataPath + "/gd.fun"; FileStream fStream = new FileStream(path, FileMode.Create); GameDataSL gdsl = new GameDataSL(true); formatter.Serialize(fStream, gdsl); fStream.Close(); }
public static GameDataSL LoadData() { string path = Application.persistentDataPath + "/gd.fun"; if (File.Exists(path)) { BinaryFormatter formatter = new BinaryFormatter(); FileStream fStream = new FileStream(path, FileMode.Open); GameDataSL gdsl = formatter.Deserialize(fStream) as GameDataSL; fStream.Close(); return(gdsl); } else { return(null); } }
private void Awake() { if (Instance == null) { Instance = this; GameDataSL gdsl = SaveLoadSystem.LoadData(); maxTime = gdsl.maxTime; increaseTime = gdsl.increaseTime; coins = gdsl.coins; priceMaxTime = gdsl.priceMaxTime; priceIncreaseTime = gdsl.priceIncreaseTime; bestScore = gdsl.bestScore; } else if (Instance != this) { Destroy(gameObject); return; } DontDestroyOnLoad(gameObject); }