Simple and easy to use serializable dictionary. Supports any type which can be serialzied by unity as key or value.
You can either add this repository as git package through unity package manager (click plus sign in package manager and select "Add package from git URL..."), clone as submodule into your project's ./Packages
directory or simple copy-paste code into your project.
For each key-value pair, dictionary type should be excplicitly defined and marked as [Serializable]
using SerializedDict;
using System;
using UnityEngine;
[Serializable]
public class ColorsDictionary : SerializedDictionary<string, Color>
{ }
Any serializable type is supported for key and value. You can even use SerializableDictionary
itself for key and value if you really want it:
using SerializedDict;
using System;
using UnityEngine;
[Serializable]
public class ColorsDictionary : SerializedDictionary<string, Color>
{ }
[Serializable]
public class BoundsDictionary : SerializedDictionary<int, Bounds>
{ }
[Serializable]
public class InsaneDictionary : SerializedDictionary<ColorsDictionary, BoundsDictionary>
{ }
Because of the way its serialized, changing or removing values is O(N) , so try to avoid it in runtime and use basic Dictionary<>
instead