8,290
edits
(expanded the article quite a bit) |
m (a bit more detail) |
||
Line 8: | Line 8: | ||
== How Serialization Works for Qud == | == How Serialization Works for Qud == | ||
In many cases, you can simply include the the <code>[Serializable]</code> attribute at the top of your class definition, and Qud's game engine will take care of serializing all of your <code>public</code> class fields for you. Specifically, Qud is capable or correctly serializing all intrinsic types (such as <code>string</code>, <code>int</code>, etc.) as well as containers of those types (such as <code>List<string></code>). If your class only uses intrinsic types, the <code>[Serializable]</code> attribute should be all that you need. Qud will properly save and load your data without further effort. Note that <code>private</code> and <code> | In many cases, you can simply include the the <code>[Serializable]</code> attribute at the top of your class definition, and Qud's game engine will take care of serializing all of your <code>public</code> class fields for you. Specifically, Qud is capable or correctly serializing all intrinsic types (such as <code>string</code>, <code>int</code>, etc.) as well as containers of those types (such as <code>List<string></code>). If your class only uses intrinsic types, the <code>[Serializable]</code> attribute should be all that you need. Qud will properly save and load your data without further effort. Note that <code>private</code>, <code>protected</code>, and <code>static</code> class fields are not serialized by default. If you want the values associated with private or protected class fields to be retained through a save and load, you need to mark each individual private or protected field with a <code>[SerializeField]</code> attribute. Static fields can never be serialized. See [https://docs.unity3d.com/ScriptReference/SerializeField.html the Unity docs] for more information about serializable fields ''(note that the GameObject discussed on that linked page is not related to the GameObject type commonly used in Qud)''. | ||
Here is an example of the basic concepts discussed above:<syntaxhighlight lang="c#"> | Here is an example of the basic concepts discussed above:<syntaxhighlight lang="c#"> |