CD-ROOM/Assets/Scripts/SaveSystem.cs
Gerard Gascón 341a877b4a init
2025-04-24 17:37:25 +02:00

34 lines
1 KiB
C#

using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using UnityEngine;
public static class SaveSystem{
public static void SavePlayer(PlayerController player){
BinaryFormatter formatter = new BinaryFormatter();
string path = Application.persistentDataPath + "/gaviota.man";
FileStream stream = new FileStream(path, FileMode.Create);
PlayerData data = new PlayerData(player);
formatter.Serialize(stream, data);
stream.Close();
}
public static PlayerData LoadPlayer(){
string path = Application.persistentDataPath + "/gaviota.man";
if (File.Exists(path)){
BinaryFormatter formatter = new BinaryFormatter();
FileStream stream = new FileStream(path, FileMode.Open);
PlayerData data = formatter.Deserialize(stream) as PlayerData;
stream.Close();
return data;
}else{
Debug.LogError("Save file not found in " + path);
return null;
}
}
}