using System; using System.IO; using System.Runtime.Serialization.Formatters.Binary; using UnityEngine; using UnityEngine.SceneManagement; using PlayerSpawnPointScript; public class SaveSystem { public static void SavePointUpdate(SavePoint save) { BinaryFormatter formatter = new BinaryFormatter(); string path = Application.persistentDataPath + "/SP.txt"; FileStream stream = new FileStream(path, FileMode.Create); SavePointData data = new SavePointData(save); formatter.Serialize(stream,data); stream.Close(); } public static SavePointData LoadSavePoint() { string path = Application.persistentDataPath + "/SP.txt"; if (File.Exists(path)) { BinaryFormatter formatter = new BinaryFormatter(); FileStream stream = new FileStream(path, FileMode.Open); SavePointData data = formatter.Deserialize(stream) as SavePointData; stream.Close(); return data; } else { return null; } } public static void NewGame() { BinaryFormatter formatter = new BinaryFormatter(); string path = Application.persistentDataPath + "/SP.txt"; FileStream stream = new FileStream(path, FileMode.Create); SavePointData data = new SavePointData(new Vector2(PlayerSpawnPointScript.PlayerSpawnPoint.startPoint.transform.position.x, PlayerSpawnPointScript.PlayerSpawnPoint.startPoint.transform.position.y)); //SavePointData data = new SavePointData(new Vector2(GameObject.Find("StartPoint").transform.position.x, GameObject.Find("StartPoint").transform.position.y)); formatter.Serialize(stream, data); stream.Close(); } }