I need to create a popup (or list box-type control) in an editor window that allows the user to make multiple selections. I gather from other threads (such as Custom inspector multi-select enum dropdown? - Questions & Answers - Unity Discussions) that one can use an enum for this, but this seems to require that I enumerate not just every item in the list, but every possible combination of items in the list. I have (potentially) very long lists of as many as a hundred items, and trying to deal with every possible combination of those items would be extremely awkward. (The lists are generated from previous user input as well, so the enum would have to happen dynamically.)
I also thought about using a button for each member of the list, but because of the potential length that creates far too much clutter.
Am I missing some obvious implementation of such a multiple-selection list box? Or am I incorrect about the way the enum would have to work? (Or, ultimately, is there any other editing system in the works so I’m not having to use the ancient GUI system to create editor extensions?)
Not sure what your exact problem is, wither it’s a popup menu in the final build as an interactable UI or a Custom inspector for your plugin users but if it’s the later try using this,
EditorGUI.Popup this will help you specify the list to portray and the index you’re on in that list, to make sure the value stays the same you can do something like this in your drawer,
private bool start = true;
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
if (start)
{
start = false;
for (int i = 0; i < list.length; i++)
{
if (list[i] == property.stringValue)
{
"Index in your attribute extended class" = i;
}
}
}
"Index in your attribute extended class" = EditorGUI.Popup(position,property.name, "Index in your attribute extended class" , list);
property.stringValue = list["Index in your attribute extended class"];
}
Thanks for your reply! I’m using it in an EditorWindow as part of an asset I’m building. Currently I’m just using the normal EditorGUILayout.Popup, for instance like this:
where selectedStory is the int index and storyList an array of strings.
This of course makes my users select one item, click “Add”, click to open the popup again and select another item, click “Add”, etc. It works, but can be very tedious if you have several items to add.
I’m not very familiar with property drawers, so forgive me if I’m missing something, but does your code keep multiple items in the EditorGUI.Popup checked/selected? It appears that “Index in your attribute extended class” is still a single index, and the popup will still just show one item selected at a time. Or is there some way that it is modifying the actual EditorGUI.Popup so that it takes an array (or something) as the index position?
Oh, I misunderstood your question then. I thought you wanted a single selection popup list, sadly thought I can not help you with what you are looking for at the moment as I never tried it myself, I will look up into it as soon as I have some free time, as for my code it checks what the saved value in the property is so that when you change the values in the array the value of that property stays the same.
Thanks for the info! That’s still not what I’m asking, but it’s very cool to know that (and will help with some of the long alpha lists I’m creating). How do you keep the slash character from showing up in the main list? My attempt keeps showing the slash in the main popup menu along with the first option of the submenu. Can you show me the code behind your menu jpg?
What I’m trying to do is allow multiple simultaneous selections, such as being able to select A, B, and C in a popup list (instead of the default behavior, which is to only allow one choice, such as A or B or C, but not more than one of these).
Hey @karl_jones ,
Could you provide any link, piece of code or anything helpful which how I can use GenericMenu for multi selection dropdown menu ? (I’ve made dropdown menu with GenericMenu before)