[Released] Dictionaries are now supported !!!! :D

:smile:Just kidding, I went through a lot of hard work and research to get to this stage, I am still testing it, nailing out bugs, and will upload to asset store soon. I’m going to solve Dictionary for Unity once and for all!

The Unity Dictionary Paradox
(Read this section if you are unfamiliar with Dictionary<K,V> )

Its now Version 5.4 and Unity still refuses to implement serializable and inspectable Dictionaries.
But us programmers, we loves Dictionaries to put better organize our logic together.

Some of us gave up using Dictionary, and try some gimmicky workaround, such as double array:(

Some turned to solution like SQLite… But this is solving problem by introducing another problem:eyes:

I Know some solution

Me too, I tried all the Dictionary solutions in Asset Store, couples of inspector enhancement plugins, but none of them is convincing enough to make me use Dictionary in unity.

The common problems are:

  • Ugly
  • not real Dictionary (simulated with 2 lists, but List can contain duplicates, Dictionary can’t)
  • Doesn’t behave like Dictionary in code (such as you must access its member like dict.Value)
  • Pain in the ars to setup (None of them shows up in the inspector without writing a custom PropertyDrawer for each derived Dictionary class in a new file in a different directory:face_with_spiral_eyes:)
  • Limited (such as you cant use GameObject as key)
  • VERY Ugly or not working when using complex types or nesting

So you solved all above problems?

Yes I solved 100% of the problem 97% of times, lets look at how I tackles those problems

1. NOT UGLY

I’m using the fancy new ReorderableList in UnityEditorInternal, it doesn’t have Dictionary support, and its undocumented, so I’ve done a lot of hacking to get this in the inspector, not bad ey?:smile:

Because all the input boxes for int, float, string etc are the same, I added the Type hint next to the variable name, It can’t detect the exact name of a type, but still does the job of letting you distinguish between similar looking inputs

2.+3. almost Real Dict
okay, its not derived from Dictionary, but I’ve mimicked almost all interfaces, It still uses an actual System.Collections.Generic.Dictionary object at its core, so functionality and performance wise are the same

check out screenshot below

4. Never write Dictionary Editor || Inspector || PropertyDrawer again
Not Simple setup, not 2 line code, Just declare your Dictionary and go, Lets see it in Action

[Serializable]
public class MyCustomDict : Dict<GameObject, float>{};

MAGIC!:sunglasses:
All other solutions requires you to

  • create your own class derived from a base class
  • go to Editor Folder
  • create another file
  • create another class, derived from a base editor class

No more Jumping back and forth when managing your own Dictionaries

5. Create Any key Value Dictionary
Remember, Dictionaries cannot have duplicate or null keys, so what happens if you get duplicated keys or null keys?
no problems, my solution handles it for you.

  • Duplicated or invalid key will be highlighted in red
  • Entries with duplicated keys will not be available in runtime
  • Entries with duplicated keys will still be saved and serialized in editor, so you don’t lose any data
  • In runtime, you cannot get duplicated keys just like native Dictionary

Heck, create a <bool, bool> Dictionary if you desire

6. Complex Types and nesting
Believe me when I said I tried all other solutions, and none of them work well in this field, I have to Deduct 3% from my 100% score because this is still not perfect
Check it out
Code here

[SerializeField]
ComplexDict IHopeILookOk;

[Serializable]
public struct ComplexStruct{
    public int a;
    public float b;
    public Quaternion VeryLongNameIsAGoodPractice;
}
[Serializable]
public class ComplexDict : Dict<string, ComplexStruct>{}


Its ugly by my standard, but thats Mainly I did not write a propertyDrawer for that ComplexStruct.
BUT, it is still usable, the slider on the top controls the Key Value Divider, so you can have Big value small key, or big key small value. The point is even if your inspector tab is very narrow, you could still see your elements by adjusting the divider

As you see, the divider is a really powerful feature, that let the Dictionary take on any kind of complex type without having to worry about not displaying properly


Check out nesting in action

Are you drooling for it now?
I’ll upload it very soon WITH Source code of course, so hold on to your saliva and PRAY Unity review it fast




2608371--182891--interfaces.png

Partially fixes nested Dictionary

now that child Dictionary shows correct result

whats still broken:

  • when adding entry to child Dictionary, it still adds to all other child dictionary
  • when one of the child dictionary is folded, other child dictionary shows wrong result

2608832--182926--nestedDict.png

Check it out, All bugs nailed!

2608995--182945--IHopeILookOk.gif

1 Like

Submitted to the asset store, stay tuned!

Any updates?

Damn, this looks nice mate :wink:

huh… Is there an actual way to have an IDE in unity as it seems to be in your screenshots ?
What kind of black magic is this ?

Script Inspector maybe?

Probably. Thanks :slight_smile:

wow a full year have passed, and i finally got a chance to submit it to the store, it is now live :slight_smile:
I’ll give out 10 keys for people willing to write out honest reviews, please PM me about it

1 Like

HI ! I’ve bought the Dictator, tried it, crashes …:frowning:
It should be working with custom classes, or not?
in the editor it works fine, but when I try to look at the"Dict" runtime the whole Unity crashes

I fill up the dict run time, with 300 - 500 key - value.

using Unity 2017.1.1f1

Arany 666 please check your inbox

edit: fixed op images

3248513--250023--complex.PNG
3248513--250024--complex1.PNG
3248513--250025--complex2.PNG

Hi,

I’ve just bought this plugin because i have a lot of problems in trying to implements Dictionary compatible with Unity Inspector.
I’ve tried this int my project but it doesn’t seem to be atapt to my problem.
I cant inspect the second nested dictionary and sometimes it gives me some strange errors in the console.
(Another small bug: the foldoutArrow is inside the key field)

using System;
using System.Collections.Generic;
using UnityEngine;

public class PlayerController : TankStateController //it's monobehaviour
{
    public CiaoClips ciao;
    public CiaoClipsDict ciaoDict;
}

[Serializable]
public class Clips
{
    [SerializeField]
    public List<AudioClip> collection;

    public Clips() : base()
    {
        collection = new List<AudioClip>();
    }
}

[Serializable]
public class LocClips : Dict<SystemLanguage, Clips> { }

[Serializable]
public class CiaoClips
{
    [SerializeField, Range(0, 100)] private int priority;
    [SerializeField] private LocClips collection;
}

[Serializable]
public class CiaoClipsDict : Dict<string, CiaoClips> { }

If someone can help me please reply!

Last thing, I think that implementing a constructor for the Dict class would be nice in order to have more control on the usage of the dict class.

Thank you

Hey Astrokoala, your plugin is awesome and I love it, but has this small graphical issue that drives me crazy, do you know how I can fix that? Thank you :slight_smile:

Hi mate,

I know this is two years late so you’ve probably sorted this out by now but just in case, I found a fix for this!

In the dictator editor script, at line 317, the Foldout is rendered…
Added a line above that (but still in the if statement) with:

pos.height = EditorGUIUtility.singleLineHeight;