[Released] Serializable Dictionary Lite - Now allowing custom editor for key field

Serializable Dictionary Lite


Website: RotaryHeart.com
Product Wiki: Online

Version 2.6.9.6
Available Now: Asset Store
[Release Notes]( [Released] Serializable Dictionary Lite - Now allowing custom editor for key field page-6#post-8649867)

Pro version available

UPM Version available

Serializable Dictionary Lite is a system that I built for my projects since I needed to have a database like structure that could be modified on the editor by any designer. It can easily be used for any kind of serializable type either for key or for value. It contains a script that handles the inspector draw in an elegant and simple UI. The best part of the system is that it’s easy to setup and it doesn’t require any new scripts. All you have to do is declare your dictionary like:

[Serializable]
public class MyDctionary : SerializableDictionaryBase<Key, Value> { }

Where key and value can be either Unity components or a simple type.

[Serializable]
public class MyDictionary : SerializableDictionaryBase<Material, GameObject> { }
[Serializable]
public class MyDictionary : SerializableDictionaryBase<string, float> { }
[Serializable]
public class MyDictionary : SerializableDictionaryBase<string, MyCustomClass> { }




6 Likes

Hey there thats looking great ! First of all thanks for replying on my thread ! :slight_smile: If you dont mind, i would love to take a look at your package ! Its looking pretty good in the pictures ! ^^

Great news! Version 1.0 is live on the asset store!

Product wiki has been published. It can be found at my page Wiki section

Version 1.0.1 has been submitted to the asset store for review. This version includes:

  • Removed the checks for UNITY_EDITOR on the dictionary class. This made the built shared assets file to be corrupt.

Version 1.0.1 is now live

Unfortunately this is not what I wanted to use (not your fault, what you’ve written is awesome)

I wanted to serialize data into json format for google firebase in a nested format like this:
(to allow maximum nosql performance)

{
        key1: {
                int1: 0,
                int2: 12
        },....
        key7: {
                int1: 0,
                int2: 12
        }
}

From what I see in plugin will not produce the wanted format

        [UnityEngine.SerializeField] private TKey[] _keyValues;

        [UnityEngine.SerializeField] private TKey[] _keys;

        [UnityEngine.SerializeField] private TValue[] _values;

I’ll try to create a custom UnityEngine.ISerializationCallbackReceiver.OnBeforeSerialize()

Main challenge is to get the key names to appear in the root position of the json… not sure if this is possible

Probably have to use this:

Or jsonbuilder:

@IVPathfinder I'm sorry that this doesn't provide the output you expect. Perhaps we could work it out, but I fail to understand what you are trying to do. Can you provide a more in depth example?

Version 1.1 has been submitted to the asset store for review. This version includes:

  • Fixed an issue with int as key values.

  • Included new Quaternion better layout.

1 Like

Version 1.1 is now live on the asset store.

Hi, I seem to have issues when my Value Type is an array of Unity Objects, e.g. SerializableDictionaryBase<string, GameObject[ ]>. In this case, the Property Drawer crashes as ValuesProp seems to be null.

This is the Stack Trace:
NullReferenceException: Object reference not set to an instance of an object
RotaryHeart.Lib.SerializableDictionary.DictionaryPropertyDrawer.GetPropertyHeight (UnityEditor.SerializedProperty property, UnityEngine.GUIContent label) (at Assets/SerializableDictionary/SerializableDictionary/Editor/DictionaryPropertyDrawer.cs:71)

My code is as follows:

[SerializeField]
private ObjectsDictionary _objects;

[System.Serializable]
public class ObjectsDictionary : SerializableDictionaryBase<string, GameObject[ ]> { }

EDIT:
Never mind, it seems that you can solve this by using a class with the array as a field, like so:

[SerializeField]
private ObjectsDictionary _objects;

[System.Serializable]
public class ObjectsDictionary : SerializableDictionaryBase<string, MyObjects> { }

[System.Serializable]
public class MyObjects
{
public GameObject[ ] objects;
}

Hello,

Unfortunately I haven’t found a way to allow arrays as values. Unity doesn’t recognize them as a SerializedProperty, that’s why it throws that error, so the workaround is to wrap them in a class the way you already did.

1 Like

This seems to not work when used within a ScriptableObject. After saving the project and reloading, the values are lost.

What do you mean? The example provided is with a ScriptableObject and it works fine.

Version 1.2 has been submitted to the asset store for review. This version includes:

  • Fixed a bug where values that contains other serializable dictionary were being synchronized.

Version 1.2 is now live on the asset store!!

Hello, thank you for update. But unfortunately after update to 1.2 I have same issues with synchronized dictionaries and Enums. I uploaded the file to reproduce the problems.

Here is screenshot:
https://prnt.sc/j65dp1

3464194--274873--SpellsDB.cs (1.08 KB)

That’s odd, can you remove the asset and import it back. Make sure to download the update. I used your script for figuring out the issue and I don’t have that synchronized error anymore. As for the Enum I am still trying to figure out how to allow a custom default value.

1 Like

Thank you. Really I reimported asset but didn't updated in download manager. Noob... =)
Issue with synchronized dictionaries is fixed. Nice, thank you vary much. Waiting for further updates.
And one little advice, update version of asset in documentation file for better understanding.

Good to know that is working now. That is the documentation version, not the asset version I will modify it to include both versions.