- Home /
im getting a serialization exception eror in my load method
using System.Runtime.Serialization.Formatters.Binary;
using UnityEngine;
using System.IO;
public static class SaveSystem
{
public static void SaveData(Calculator calculator)
{
BinaryFormatter formatter = new BinaryFormatter();
string path = Application.persistentDataPath + "Alma3Gold.formula";
FileStream stream = new FileStream(path, FileMode.Create);
Data data = new Data(calculator);
formatter.Serialize(stream, data);
}
public static Data LoadData(Calculator calculator)
{
string path = Application.persistentDataPath + "Alma3Gold.formula";
Data data = new Data(calculator);
if (File.Exists(path))
{
BinaryFormatter formatter = new BinaryFormatter();
FileStream stream = new FileStream(path, FileMode.Open);
data = formatter.Deserialize(stream) as Data;
stream.Close();
}
else
{
Debug.Log("Save file not found in " + path);
data.PRICE = 0;
}
return data;
}
}
Comment