I am currently trying to make Unity load a level from Resources and then deserialize it through BinaryFormatter to get level information.
public static LevelInformation LoadLevelOfficial (string name) {
Object levelFile = Resources.Load("/Levels/" + name + ".lvl");
if (levelFile) {
BinaryFormatter formatter = new BinaryFormatter ();
FileStream stream = new FileStream (levelFile, FileMode.Open);
LevelInformation data = formatter.Deserialize (stream) as LevelInformation;
stream.Close ();
return data;
} else {
Debug.LogError ("No official level called " + name + "can be found in the game files!");
return null;
}
}
The code crashes at the FileStream line, telling me I can’t deserialize an object directly.
Assets/Resources/Scripts/SaveSys/SaveSystem.cs(100,40): error CS1503: Argument `#1' cannot convert `UnityEngine.Object' expression to type `System.IntPtr'
Any way to work around this?