Search Results for

    Show / Hide Table of Contents

    Class SerializableDictionary<TKey, TValue>

    A Unity serializable System.Collections.Generic.Dictionary<TKey, TValue>.

    Inheritance
    System.Object
    System.Collections.Generic.Dictionary<TKey, TValue>
    SerializableDictionary<TKey, TValue>
    Implements
    System.Collections.Generic.IDictionary<TKey, TValue>
    System.Collections.Generic.ICollection<System.Collections.Generic.KeyValuePair<TKey, TValue>>
    System.Collections.Generic.IReadOnlyDictionary<TKey, TValue>
    System.Collections.Generic.IReadOnlyCollection<System.Collections.Generic.KeyValuePair<TKey, TValue>>
    System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<TKey, TValue>>
    System.Collections.IDictionary
    System.Collections.ICollection
    System.Collections.IEnumerable
    System.Runtime.Serialization.IDeserializationCallback
    System.Runtime.Serialization.ISerializable
    UnityEngine.ISerializationCallbackReceiver
    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 Source

    SerializableDictionary()

    Type constructor.

    Declaration
    public SerializableDictionary()
    Exceptions
    Type Condition
    UnsupportedRuntimeException

    Not supported on DOTS Runtime.

    Methods

    | Improve this Doc View Source

    GetSerializedDataLength()

    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.

    | Improve this Doc View Source

    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.

    | Improve this Doc View Source

    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.

    | Improve this Doc View Source

    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.

    | Improve this Doc View Source

    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.

    | Improve this Doc View Source

    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.

    | Improve this Doc View Source

    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.

    Implements

    System.Collections.Generic.IDictionary<TKey, TValue>
    System.Collections.Generic.ICollection<T>
    System.Collections.Generic.IReadOnlyDictionary<TKey, TValue>
    System.Collections.Generic.IReadOnlyCollection<T>
    System.Collections.Generic.IEnumerable<T>
    System.Collections.IDictionary
    System.Collections.ICollection
    System.Collections.IEnumerable
    System.Runtime.Serialization.IDeserializationCallback
    System.Runtime.Serialization.ISerializable
    UnityEngine.ISerializationCallbackReceiver
    • Improve this Doc
    • View Source
    In This Article
    Back to top Built on 2024-01-01 against 1f69a68.
    Generated by Dox+DocFX.