Custom ListBox

I’ve made a custom list box so you can select items from a list, but I had a few questions about recommended design/performance.

For the items within the selection list i’ve been using simple Button objects, but I was wondering if toggles might be better, since buttons don’t really support a selected state and I’ve had to fake it by changing the button ColorBlock.

On the other hand, I’m not sure toggle groups support multiple selection, and their look is completely wrong for a listBox. I guess I could edit the prefab on the toggle to be more appropriate.

Which sounds better? Or something entirely custom using only images and a custom script that handles all mouse events?

toggle is just a type of Selectable that keeps track of a boolean (and sets an image according to it’s state)

the toggle group simply forces only the latest ‘true’ state to stick (by setting all others to false)

so using your own button script or even a state/tag/layer via some arbitrary code is fine.
alternatively you could let your list keep track of the selected item.

it’s unlikely this will have any impact on performance, unless you need to keep track of the states of each item.
In which case store then in a selected and unselected array, so you can easily decide which is where.
It’s unlikely you will need to cycle through all lets say worst case 1000 items every frame.

Apparently unity 5.2 supports a drop-down component which was half the reason I made the list to begin with (as a sub-component.)

seems my work might be a bit moot now.

If iteration performance is an issue in what @Freezy said, it’s a good practice to use generic HashSet. It’s trimmed down to iterating, and it doesn’t have an indexer since objects in HashSet have no order (so you can not use yourSet[0] for example), but it’s numerous times faster than other, indexed collections. Now (that is since was coding a library for something completely different and I wanted to save every millisecond of performance possible) I use HashSet always when I don’t need to get objects by index.

I know it doesn’t answer your question directly, but could help in some ways.