public void LoadWinPoints() { WinPointData winPointData = SaveSystem.LoadWinPoints(); winPointCounter.winPoints = winPointData.winPoints; winPointCounter.purchaseUnlockCost = winPointData.purchaseUnlockCost; winPointCounter.UpdateWinTrackers(); }
//vvv SAVE vvv public static void SaveWinPoints(WinPointCounter winPointCounter) { BinaryFormatter formatter = new BinaryFormatter(); string path = Application.persistentDataPath + "/winPoints.save"; FileStream stream = new FileStream(path, FileMode.Create); WinPointData data = new WinPointData(winPointCounter); formatter.Serialize(stream, data); stream.Close(); }
//vvv LOAD vvv public static WinPointData LoadWinPoints() { string path = Application.persistentDataPath + "/winPoints.save"; if (File.Exists(path)) { BinaryFormatter formatter = new BinaryFormatter(); FileStream stream = new FileStream(path, FileMode.Open); WinPointData data = formatter.Deserialize(stream) as WinPointData; stream.Close(); return(data); } else { Debug.LogError("No Save File in: " + path); return(null); } }