I’ve created an AudioManager Monobehavior for handling all audio in my 2D platformer. As part of this behavior, it holds a public Dictionary of type Dictionary. I wanted to set these values in the editor so that I could have a dictionary of sound clips with names, but the Dictionary type apparently isn’t editable in the Editor.
Is there a better way to do this or am I limited to this class? I don’t mind using this, but I don’t know if there are any performance issues. I’d like to see if there’s a different way to proceed before I commit to this path. Thank you!
TL:DR - is there a class that works like a Dictionary, but is serializable in Unity’s editor window?
I ended up creating a class with an array of Serializable classes, instead of the Dictionary. However, when the game starts, I parse the array and add all contents to a Dictionary; basically, I’m using an array just to get it to display in the Editor (while in-game, I have the one-to-one lookup).
Like this:
public void OnEnable () {
// Make sure that the array is populated. If not, create a new instance.
if (myEntries == null) { myEntries = new AudioEntry[0]; }
// Also, here, we need to actually populate our dictionary item.
lookupTable = new Dictionary<string, AudioClip>();
foreach (AudioEntry entry in myEntries) {
lookupTable.Add(entry.Name, entry.value);
}
}