Game Development Reference
In-Depth Information
{
//Deserialize the data from the stream
output = (T)serializer.Deserialize(stream);
}
}
catch { }
//Return the deserialized output
return output;
}
Tip
If you want to keep things simple, you can also convert the load function to always pass
a byte array for all platforms, and get rid of the first deserialization method.
Finally, one last fix. If you build for Windows 8 now, you will still have one error that re-
mains in the SerializationHelper script. This is because the implementation of the
MemoryStream class on Windows 8 doesn't have a GetStream method. Now, you can
use another preprocessor directive and use a different implementation for Windows 8.
However, in this case, if you simply switch to using the ToArray() method, it'll give
you the result you want.
Note
This may not always be the case! If you need to encode data for text or images, you may
find that using ToArray doesn't fit because it can output the data differently, and you
may potentially lose some data in certain formats. Just test and check whether it still be-
haves as you require!
Build note
Currently, there have been a few inconsistencies among the builds of Unity. In some
builds, the project works fine; in others, it crashes when you try to use the singleton
classes.
In testing, it seems as though the execution order of singletons is altered, and they are ac-
tually destroyed after they are created. This mostly seems to affect the .NET-based builds.
Search WWH ::




Custom Search