Ok, I give up :). I spent 30 minutes googling for what I thought it’s going to be an “easy peasy” . Turns out not really.
I have a long list of items (let’s say 500) that I’d like to allow the user to quickly narrow-down, pretty much like Unity does when you want to add a new Component to an object.
What I’m after is your ubiquitous dropdown list which has the very 21st century functionality of reducing its options based on what you type in a text field. From what I see, this is not exactly a trivial component in the Unity Editor.
Am I forced to do this as a two-pieces UI component? One text field and one popup to display the items?
Another thought would be text field + scroll view, and the scroll view would be populated by labels. This seems the option that Unity developers chose for their own Component selection popup.
Sounds useful… seems like someone might have already made it but I have no idea how to google for it.
Are you aware the full source for UnityEngine.UI is freely available for you to peruse? You could probably take an InputField and a DropDown and mash them together into some unholy string filtering picklist…
If you haven’t already, you could also try searching the Unity asset store.
Making such a filter sounds like a one-day intermediate-level development project, although a couple possible wrinkles occur to me. (The main one being that if your list of items is large enough that you want to filter it, it may also be large enough that you want to use a virtual scroll with object pooling for performance reasons, and I bet Unity doesn’t have that built-in.)
@Kurt-Dekker didn’t know I could peer in UnityEngine.UI. Is it C#?
@Antistone that’s a fair assessment of the difficulty, yes. And I’m probably going to go for it if nobody shows up saying “hey silly” in the next few days. Judging by both of yours number of posts though, seems like you’ve seen it all .
I haven’t searched the Asset Store since I thought Google would include those results. I did a search now and came up only with game-related assets.
Looking at EditorGUILayout.BeginScrollView, it seems to not be virtual scroll friendly. It automatically gets the size of the content in it. I could fool it by adding an empty image I guess (or use GUILayout.BeginArea but one person seemed to have trouble with this and ScrollView back in 2011 ( Help with scroll bars in an Editor Window ) which is so very recent).
I’d prefer a dedicated scrollbar component but from what I see, the ScrollView is the only option.
Yes, if you install it from a package it’s all there, and you can also grab it off github. Either way, it might give you insight to creating what you need.
Keep in mind this might be fiddly on mobile: the keyboard needs to stay active in the filter string field while the filtered-down list is also scrollable by touch, which might not even be possible depending on OS-specific behavior regarding touching outside of the keyboard when it is active.
But what do I care about mobile? This is an editor-only component I’m talking about . Perhaps you missed that in the topic title . So now that you know, maybe you know of editor components that might already do this? If not, I’m going to code one and give it for free to the community
Oh that’s a LOT easier. The naive way is to just code it up in OnInspectorGUI() and be done with it. I don’t know of existing stuff but maybe there is.
Have an input field
Use the contents to filter the list
Iterate and list the items with some way to pick them