private void SaveObject<T>(T t)
{
string name = string.Format("path{0}.dat", t.ToString());
FileStream fs = new FileStream(name, FileMode.OpenOrCreate);
BinaryFormatter formatter = new BinaryFormatter();
try
{
formatter.Serialize(fs, t);
}
catch (Exception ex)
{
Debug.Log(ex.Message);
}
finally
{
fs.Close();
}
}
private T LoadObject<T>() where T : new()
{
T t = new T();
string name = string.Format("path{0}.dat", t.ToString());
FileStream fs = new FileStream(name, FileMode.Open);
BinaryFormatter formatter = new BinaryFormatter();
try
{
t = (T)formatter.Deserialize(fs);
}
catch (Exception ex)
{
Debug.Log(ex.Message);
}
finally
{
fs.Close();
}
return t;
}