简体   繁体   中英

Using [Serializable] with mscorlib (Unity)

I'm building an iOS game using Unity and in the docs for optimisation, it says:

Don’t use anything that lives in System.dll or System.Xml.dll in your code. These libraries are not compatible with micro mscorlib.

Here's the link to that page .

In my code, to save game data I have a class like so:

[Serializable]
class GeneralGameData {
    public bool muteMusic;
    public bool muteSoundFX;
    public bool muteVibration;
    public int highestScoreAchieved;
}

Which requires:

Using System;

When I run the game, it seems ok with mscorlib to use this but get a nasty crash, a crash that kills unity every now and again and also the game at random points. I suspect it might be to do with this.

Can anyone point me in the right direction to how to save serialized data with micro mscorlib?

Cheers.

You can have a look at the Mono compatibility reference to see which elements are not available in micro mscorlib.

You'll notice that SerializableAttribute (namespace System, assembly mscorlib) is available in .NET 2.0, 2.0 subset, Web player and Micro. The use of [Serializable] should not be at fault here. However, your actual serialization code may indirectly rely on something that is not available in the micro mscorelib. You can always use .NET Reflector to inspect the serializer code to verify.

You can have a look here for some ideas on how to save game data (as well as some of the issues you may encounter around serialization in general).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM