Class SerializableDictionary<TKey, TValue>
A Unity serializable System.Collections.Generic.Dictionary<TKey, TValue>.
Inheritance
Implements
Namespace: GDX.Collections.Generic
Syntax
[Serializable]
[VisualScriptingCompatible((short)1)]
public class SerializableDictionary<TKey, TValue> : Dictionary<TKey, TValue>, IDictionary<TKey, TValue>, ICollection<KeyValuePair<TKey, TValue>>, IReadOnlyDictionary<TKey, TValue>, IReadOnlyCollection<KeyValuePair<TKey, TValue>>, IEnumerable<KeyValuePair<TKey, TValue>>, IDictionary, ICollection, IEnumerable, IDeserializationCallback, ISerializable, ISerializationCallbackReceiver
Type Parameters
| Name | Description |
|---|---|
| TKey | The dictionary's key System.Type. |
| TValue | The dictionary's value System.Type. |
Remarks
This will NOT work with System.Object based objects, use UnityEngine.Object if you must. While .NET has solutions for creating custom serialization paths, Unity uses its own system to serialize data into YAML structures. This also assumes that the types provided can be serialized by Unity.
The process of serializing and deserializing this dictionary should not be considered performant.
The property drawer will not show structs, it will be blank. It does work however if done through code.
Constructors
| Improve this Doc View SourceSerializableDictionary()
Type constructor.
Declaration
public SerializableDictionary()
Exceptions
| Type | Condition |
|---|---|
| UnsupportedRuntimeException | Not supported on DOTS Runtime. |
Methods
| Improve this Doc View SourceGetSerializedDataLength()
Get the length of the serialized data arrays.
Declaration
public int GetSerializedDataLength()
Returns
| Type | Description |
|---|---|
| System.Int32 | An integer value representing the count. |
Exceptions
| Type | Condition |
|---|---|
| UnsupportedRuntimeException | Not supported on DOTS Runtime. |
IsSerializableType(Type)
Is the type capable of being serialized by the
SerializableDictionary<TKey, TValue>, utilizing Unity's own serialization system?
Declaration
public static bool IsSerializableType(Type type)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Type | type |
Returns
| Type | Description |
|---|---|
| System.Boolean | true/false if the type is valid. |
Exceptions
| Type | Condition |
|---|---|
| UnsupportedRuntimeException | Not supported on DOTS Runtime. |
LoadSerializedData(Boolean)
Load the data into the System.Collections.Generic.Dictionary<TKey, TValue> cached in the serialized data.
Declaration
public void LoadSerializedData(bool clearAfterLoad = true)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Boolean | clearAfterLoad | Should the serialized data be cleared after loading? |
Exceptions
| Type | Condition |
|---|---|
| UnsupportedRuntimeException | Not supported on DOTS Runtime. |
OnAfterDeserialize()
Rehydrate the serialized data arrays back into a cohesive System.Collections.Generic.Dictionary<TKey, TValue>.
Declaration
public void OnAfterDeserialize()
Remarks
Invoked by Unity, calls LoadSerializedData(Boolean).
Exceptions
| Type | Condition |
|---|---|
| UnsupportedRuntimeException | Not supported on DOTS Runtime. |
OnBeforeSerialize()
Build out serialized data arrays and associative data, used to rehydrate during deserialization.
Declaration
public void OnBeforeSerialize()
Remarks
Invoked by Unity, calls SaveSerializedData().
Exceptions
| Type | Condition |
|---|---|
| UnsupportedRuntimeException | Not supported on DOTS Runtime. |
OverwriteSerializedData(TKey[], TValue[])
Overwrite data in the serialized arrays with the provided data.
Declaration
public void OverwriteSerializedData(TKey[] keyArray, TValue[] valueArray)
Parameters
| Type | Name | Description |
|---|---|---|
| TKey[] | keyArray | An array of keys. |
| TValue[] | valueArray | An array of values. |
Exceptions
| Type | Condition |
|---|---|
| UnsupportedRuntimeException | Not supported on DOTS Runtime. |
SaveSerializedData()
Fill serializable arrays from dictionary data.
Declaration
public void SaveSerializedData()
Remarks
We will always create the arrays so the property drawers function nicely.
Exceptions
| Type | Condition |
|---|---|
| UnsupportedRuntimeException | Not supported on DOTS Runtime. |