Dictionary¶
The serializable dictionary allows to have the whole fully fledged functionality of System.Collections.Dictionary
but also allows to automatically serialize its values.
To create a serializable dictionary, simply inherit from TSerializableDictionary<TKey, TValue>
. For example, to create a dictionary that uses string
as their key and GameObject
as their value:
public MyDictionary : TSerializableDictionary<string, GameObject>
{ }
You can now create a dictionary that automatically serializes its values and use it as any normal dictionary:
public MyComponent : MonoBehaviour
{
public MyDictionary dictionary = new MyDictionary();
private void Awake()
{
// Add element to dictionary:
this.dictionary.Add("Hello World", this.gameObject);
// Print element added
Debug.Log(this.dictionary["Hello World"].name);
}
}