Hi everyone,
I am wondering if Unity provides serialization of their data that supports storing the data as bytes. JsonUtilitiy is really and I’m looking for a similar library to JsonUtility but for to-byte serialization.
There is the possiblity to use BinaryWriter/Reader, but it is rather inperformant.
I do my saving with binary writer, but please note that you need a container class for it, because Scripts deriving from MonoBehaviour cant use the new KeyWord, so when you deserialize it your deserialization will fail at runtime.
I Achieve this by implementing the ISerializable interface, in the container classes, and because the container classes aint derive from MonoBehaviour i can use the new Keyword at deserialization.
public void Save_Game_State()
{
try
{
BinaryFormatter bf = new BinaryFormatter();
FileStream fs = File.Create(file_path);
bf.Serialize(fs, Building_Containers);
fs.Close();
}
catch (Exception ex)
{
print("Hiba a fájlbaírásnál! - Saving(Creating, writing)");
print(ex.Message);
}
}