Unity Serialization

来源:互联网 发布:淘宝代运营 公司发展 编辑:程序博客网 时间:2024/05/16 10:54

http://blogs.unity3d.com/2012/10/25/unity-serialization/

一些要点:

What happens when an assembly is reloaded?
When you enter / exit play mode or change a script Unity has to reload the mono assemblies, that is the dll’s associated with Unity.

On the user side this is a 3 step process:

  • Pull all the serializable data out of managed land, creating an internal representation of the data on the C++ side of Unity.
  • Destroy all memory / information associated with the managed side of Unity, and reload the assemblies.
  • Reserialize the data that was saved in C++ back into managed land.

Some Serialization Rules

  • Avoid structs
  • Classes you want to be serializable need to be marked with [Serializable]
  • Public fields are serialized (so long as they reference a [Serializable] class)
  • Private fields are serialized under some circumstances (editor).
  • Mark private fields as [SerializeField] if you wish them to be serialized.
  • [NonSerialized] exists for fields that you do not want to serialize.


0 0