- Home /
Complex List in Inspector..
This question is actually Twofold.. I am able to display and/or add a single types in a List in the inspector, By declaring the list as public. For Instance, I have a list of AudioClips, and i can add elements and drag-drop audio clips in there. But I also want to associate a text with it, (for dialogue speak & display). But if i make it a list of a class (with those two elements) it doesn't show up in the inspector. Is there a way to make it happen in Unity? (I really want the ability to drag-drop audio clips instead of just doing it in the program).
Next is, What about showing dictionaries in the inspector? (With a key in addition..);
Thanks & Regards
Raj
Answer by Bunny83 · Nov 02, 2014 at 09:20 PM
If i got you right all you're missing is the System.Serializable attribute, right?
// C#
[System.Serializable]
public class DialogItem
{
public AudioClip audio;
public TextAsset text;
}
public class SomeBehaviour : MonoBehaviour
{
public List<DialogItem> dialogs;
}
You said text file so i used a TextAsset here. However if you want to input a string in the inspectorm just change the type to string. If you want a larger text area to input a text, you have to write a custom inspector for your SomeBehaviour class or a property drawer for your DialogItem class.
If you need more information, just ask ;)
This got me working for Lists. For Dictionaries, I guess i'll have to start looking into Custom Inspectors. Thanks a Lot.
Dictionaries can't be serialized at all. A custom inspector won't help here since a inspector can only work with things that are serialized. If you really need a dictionary, take a look at the new ISerializationCallbackReceiver which allows you to manually map data which can't be serialized to a data type that can be serialized. For example "a Dictionary" -> 2 arrays or Lists.
OnBeforeSerialize has exactly this case as example ;)
Answer by AVOlight · Nov 02, 2014 at 08:34 PM
Here's a great tutorial from Jasper Flick, that helped me get my head around custom inspectors. Which is what you'll need to create your own list with custom functionality, like having descriptions displayed with each element of your list
Thanks for the link. That will open up a new avenue for my learning.
Your answer

Follow this Question
Related Questions
A node in a childnode? 1 Answer
Changing Custom Object Variable 1 Answer
Create List of Dictionaries C# 2 Answers
[CustomInspector] add scriptableobject in a list always null 1 Answer