Skip to content

vape/SerializedDictionary

Repository files navigation

Serialized Dictionary

Simple and easy to use serializable dictionary. Supports any type which can be serialzied by unity as key or value.

Usage

Adding to project

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.

Code Examples

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>
{ }

Alt text

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>
{ }

Alt text

Notes

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

About

Serializable dictionary for Unity

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages