Class SerializableDictionary<TKey, TValue>
A Dictionary<TKey, TValue> that survives Unity serialization. Unity's
default serializer cannot persist generic dictionaries, so this type uses the standard
UnityEngine.ISerializationCallbackReceiver two-list pattern to convert between the
dictionary representation used at runtime and the parallel key/value lists used during
serialization. Designers can edit the contents directly via a paired UI Toolkit drawer
that displays the entries as a key-value table.
Inheritance
SerializableDictionary<TKey, TValue>
Implements
ISerializationCallbackReceiver
Assembly: ScyllaCore.dll
Syntax
[Serializable]
public class SerializableDictionary<TKey, TValue> : IDictionary<TKey, TValue>, ICollection<KeyValuePair<TKey, TValue>>, IEnumerable<KeyValuePair<TKey, TValue>>, IEnumerable, ISerializationCallbackReceiver
Type Parameters
| Name |
Description |
| TKey |
The serializable key type.
|
| TValue |
The serializable value type.
|
Constructors
SerializableDictionary()
Initializes a new empty dictionary.
Declaration
public SerializableDictionary()
SerializableDictionary(IDictionary<TKey, TValue>)
Initializes a new dictionary by copying the entries from source.
Declaration
public SerializableDictionary(IDictionary<TKey, TValue> source)
Parameters
| Type |
Name |
Description |
| IDictionary<TKey, TValue> |
source |
The source dictionary to copy from. Must not be null.
|
Exceptions
Properties
Count
The number of key-value pairs in the dictionary.
Declaration
public int Count { get; }
Property Value
IsReadOnly
Always false; this collection supports modification.
Declaration
public bool IsReadOnly { get; }
Property Value
this[TKey]
Gets or sets the value associated with the specified key. Throws
KeyNotFoundException when reading a missing key. Setting a missing
key adds it.
Declaration
public TValue this[TKey key] { get; set; }
Parameters
| Type |
Name |
Description |
| TKey |
key |
The key.
|
Property Value
| Type |
Description |
| TValue |
The value associated with the key.
|
Keys
A live collection view of the dictionary keys.
Declaration
public ICollection<TKey> Keys { get; }
Property Value
Values
A live collection view of the dictionary values.
Declaration
public ICollection<TValue> Values { get; }
Property Value
Methods
Add(KeyValuePair<TKey, TValue>)
Declaration
public void Add(KeyValuePair<TKey, TValue> item)
Parameters
Add(TKey, TValue)
Declaration
public void Add(TKey key, TValue value)
Parameters
| Type |
Name |
Description |
| TKey |
key |
|
| TValue |
value |
|
Clear()
Declaration
Contains(KeyValuePair<TKey, TValue>)
Declaration
public bool Contains(KeyValuePair<TKey, TValue> item)
Parameters
Returns
ContainsKey(TKey)
Declaration
public bool ContainsKey(TKey key)
Parameters
| Type |
Name |
Description |
| TKey |
key |
|
Returns
CopyTo(KeyValuePair<TKey, TValue>[], int)
Declaration
public void CopyTo(KeyValuePair<TKey, TValue>[] array, int arrayIndex)
Parameters
GetEnumerator()
Declaration
public IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator()
Returns
OnAfterDeserialize()
Rebuilds the dictionary from the parallel _keys and _values lists
immediately after Unity deserializes this object. Length mismatches between the
two lists are tolerated by truncating to the shorter length and emitting a warning.
Duplicate keys (which can occur when designers edit the lists in the inspector)
are skipped and a warning is emitted, leaving the first occurrence in place.
Declaration
public void OnAfterDeserialize()
OnBeforeSerialize()
Rebuilds the parallel _keys and _values lists from the live dictionary
immediately before Unity serializes this object.
Declaration
public void OnBeforeSerialize()
Remove(KeyValuePair<TKey, TValue>)
Declaration
public bool Remove(KeyValuePair<TKey, TValue> item)
Parameters
Returns
Remove(TKey)
Declaration
public bool Remove(TKey key)
Parameters
| Type |
Name |
Description |
| TKey |
key |
|
Returns
TryGetValue(TKey, out TValue)
Declaration
public bool TryGetValue(TKey key, out TValue value)
Parameters
| Type |
Name |
Description |
| TKey |
key |
|
| TValue |
value |
|
Returns
Implements
UnityEngine.ISerializationCallbackReceiver
Extension Methods