Skip to content

Instantly share code, notes, and snippets.

@ratozumbi
Created September 22, 2022 15:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ratozumbi/ece8295fd8b3001e3be7b7303b0403f6 to your computer and use it in GitHub Desktop.
Save ratozumbi/ece8295fd8b3001e3be7b7303b0403f6 to your computer and use it in GitHub Desktop.
Fake serializable dictionary
//credits: https://forum.unity.com/threads/finally-a-serializable-dictionary-for-unity-extracted-from-system-collections-generic.335797/
[Serializable]
public class MyDictionaryEntry
{
public GameObject key;
public float value;
}
[SerializeField]
private List<MyDictionaryEntry> inspectorDictionary;
private Dictionary<GameObject, float> myDictionary;
private void Awake()
{
myDictionary = new Dictionary<GameObject, float>();
foreach(MyDictionaryEntry entry in inspectorDictionary)
{
myDictionary.Add(entry.key, entry.value);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment