Skip to content

Create a serializable dictionary in Unity with all necessary error detections

License

Notifications You must be signed in to change notification settings

EduardMalkhasyan/Serializable-Dictionary-Unity

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

63 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Serializable Dictionary in Unity

Download Unity Package:

Download. Works with all Unity versions

How to Use:

Just simpy import Unity Package it contains only several scripts and it ready to use!

This SerializableDictionary provides functionality similar to Unity's Dictionary<TKey, TValue>, allowing it to be displayed in the Unity Inspector. Works also with Odin Inspector and without

Example script

public SerializableDictionary<int, string> intToStringDictionary;

all right can hold inside array

Error Detections:

It can automatically detect duplicates and display them in the Inspector mutiple duplicated keys

Also in Debugger when it will be called aaaaaaaaa

Extra Serialize Interfaces

Serialize Interfaces From Version 2.01 and above image image

Simple Example in Use

You can simply clone the project and check the results. Here is a very simple example for use

using ProjectTools;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

public class Example : MonoBehaviour
{
    [SerializeField] private Text GeorgeLabel;
    [SerializeField] private Image GeorgeImage;

    [SerializeField] private Text ThemisLabel;
    [SerializeField] private Image ThemisImage;

    [SerializeField] private SerializableDictionary<int, string> intToStringDictionary;
    [SerializeField] private SerializableDictionary<string, Color> stringToColorDictionary;
    [SerializeField] private SerializableDictionary<string, int[]> stringToIntArrayDictionary;

    private const string GeorgeName = "George";
    private const string ThemisName = "Themis";

    private void Start()
    {
        TestSetup();
    }

    public void TestSetup()
    {
        GeorgeLabel.text = intToStringDictionary[0];
        ThemisLabel.text = intToStringDictionary[1];

        GeorgeImage.color = stringToColorDictionary[GeorgeName];
        ThemisImage.color = stringToColorDictionary[ThemisName];
    }
}

image

About

Create a serializable dictionary in Unity with all necessary error detections

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages