Home

Awesome

Generic Serializable Dictionary

Lightweight and minimalist dictionary for Unity 2020.1.x with a native look and feel.

What

Why

As of 2020.1.0a Unity supports generic serialization and native support for displaying generic Lists in the inspector. But for a long time the community has wanted a generic Dictionary implementation that doesn't require you to add boilerplate for each concrete Dictionary type.

Also, personally I'm not a fan of heavily decorated or bloated inspectors that deviate from Unity's standard inspector look and feel. This dictionary aims to look and work like the standard components you already know and use.

How

The GenericDictionary class contains all the interesting bits. It implements the IDictionary interface to behave as a standard generic dictionary. But it also implements ISerializationCallback to receive serialization callbacks - upon (de)serialization it syncs the backend Dictionary with the frontend List. If there are any key collisions the property drawer displays a standard helpbox to highlight this.

No datastructures were harmed or modified when creating this: it's all just plain old System.Collections.Generic but used behind a IDictionary interface used together with Unitys generic serializer to display a native feeling Dictionary in the inspector.

Features

How to use

This repo is a UPM package by itself, so you can use Unity Package Manager

Examples can be installed from the package via Unity Package Manager.

Requirements

A Unity version with support for generic serialization (currently 2020.1.x and above).

License

Licensed under MIT, see license file.