using UnityEngine; using System.IO; using System.Runtime.Serialization.Json; public static class SaveSystem { public static bool isGameLoaded = false; public static void SavePlayer(PlayerController player) { if (player != null) { string path = System.IO.Path.Combine(Application.persistentDataPath, "player.savefile"); SaveData saveData = new SaveData(player); string saveDataJSON = JsonUtility.ToJson(saveData); using (FileStream fs = new FileStream(path, FileMode.Create)) { using (StreamWriter sw = new StreamWriter(fs)) { sw.Write(saveDataJSON); } } } else { Debug.Log("Not saved as no playerController was sent"); } } public static SaveData LoadPlayer () { SaveData result; string path = System.IO.Path.Combine(Application.persistentDataPath, "player.savefile"); if (File.Exists(path)) { using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read)) { using (StreamReader sr = new StreamReader(fs)) { string saveData = sr.ReadToEnd(); result = JsonUtility.FromJson(saveData); } } } else { Debug.LogError("Save file not found in: " + path); return null; } return result; } }