SerializableDictionary< TKeyType, TValueType > Class Template Reference

Provides a runtime System.Collections.Generic.Dictionary< Key,Value > Structure, that can be properly serialized in unity. This class is derived from, and has the functionality of a standard c# Dictionary<K,V> In order for the SerializableDictionary to show up in the editor with the correct controls: you will need to create two need classes and files in order to apply the appropriate attributes Create a non-generic class derived from SerializableDictionary. This class does not need a body, but does need to be tagged with [System.Serializable]. Create a property drawer class derived from SerializableDictionaryPropertyDrawerBase (stored in an Editor folder). This class does not need a body, but does need to be tagged with [[CustomPropertyDrawer(typeof(YourClassDerivedFromSerializableDictionary), true)]].

Detailed Description

Template Parameters
TKeyTypeDictionary Keys are object of this type. It is the programmers responsibility to make sure they are unique.
TValueTypeThis is the type of each Value stored with a key.

Public Member Functions

 SerializableDictionary ()
 Default Constructor. Initializes the Dictionary with zero elements.
 
 SerializableDictionary (int len=0)
 Initializes the Dictionary with a number of elements allocated, but does not assign any elements.
 
void Add (KeyValuePair< TKeyType, TValueType > item)
 adds the provided KeyValuePair{TKeyType, TValueType} to the dictionary. This object contains BOTH the key, and the value to be stored. if the key already exists in the dictionary an exception will be thrown.
 
void Add (TKeyType key, TValueType value)
 Add the provided key/value pair to the dictionary
 
void Clear ()
 Removes all keys and values from the dictionary.
 
bool Contains (KeyValuePair< TKeyType, TValueType > item)
 check if the dictionary contains the key specified, and if so, that the value associated with the key also matches the value in the provided parameter.
 
bool ContainsKey (TKeyType key)
 Checks to see if the specified key already exists in the dictionary
 
void CopyTo (KeyValuePair< TKeyType, TValueType >[] array, int arrayIndex)
 Used to copy the collection Keys and Values into an array of KeyValuePair{TKeyType, TValueType}
 
void EditorAdd ()
 After checking IsEditorAddKeyValid, the two new entry keys editorNewKeyValue and editorNewValueValue, will be used to create a new entry in the dictionary.
 
IEnumerator< KeyValuePair< TKeyType, TValueType > > GetEnumerator ()
 Used to get an IEnumerator{KeyValuePair{TKeyType, TValueType}} for use in iterating through the dictionary's KeyValuePairs
 
void OnAfterDeserialize ()
 Required to implement the unity ISerializationCallbackReceiver. It will convert the serialized list data into a runtime dictionary.
 
void OnBeforeSerialize ()
 Required to implement the unity ISerializationCallbackReceiver. It will convert the runtime dictionary into a simple serialize list that can be stored by unity.
 
bool Remove (KeyValuePair< TKeyType, TValueType > item)
 Removes the specified key-value pair from the dictionary.
 
bool Remove (TKeyType key)
 Removes the specified key, and it's associated value, from the dictionary
 
bool TryGetValue (TKeyType key, out TValueType value)
 Will attempt to get the value associated with the provided key. If found the function will put the value into the out parameter, value, then return true. If the key is not found in the dictionary, the function will return false, and the default value of TValueType will be put into the out parameter, value.
 

Public Attributes

TKeyType editorNewKeyValue
 This field exists for use by the propertyDrawer. It provides a place to store a new entry's Key information
 
TValueType editorNewValueValue
 This field exists for use by the propertyDrawer. It provides a place to store a new entry's Value information
 
List< TKeyType > pairKList
 Serialized version of the Key data, synchronized with the dictionary during serialization. This is what gets saved to disk, not the runtime dictionary.
 
List< TValueType > pairVList
 Serialized version of the Value data, synchronized with the dictionary during serialization. This is what gets saved to disk, not the runtime dictionary.
 

Properties

int Count [get]
 returns the number of Keys in the dictionary
 
bool IsEditorAddKeyValid [get]
 ReadOnly property that return True, if the new entry key editorNewKeyValue does not already exist in the dictionary. The new key value may not be null.
 
bool IsReadOnly [get]
 Returns true is the dictionary is ReadOnly
 
ICollection< TKeyType > Keys [get]
 returns the all the Keys in the dictionary as a Collection
 
TValueType this[TKeyType key] [get, set]
 This indexer is used to find a Particular Value in the dictionary associated with the provided key
 
ICollection< TValueType > Values [get]
 returns the all Values in the dictionary as a Collection
 
+ Inheritance diagram for SerializableDictionary< TKeyType, TValueType >: