Created
September 22, 2022 15:06
-
-
Save ratozumbi/ece8295fd8b3001e3be7b7303b0403f6 to your computer and use it in GitHub Desktop.
Fake serializable dictionary
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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