- Home /
Dropdown with list of buttons instead of toggles
Hi, I'm trying to replicate the behaviour of a standard dropdown from the Unity UI but with a list of buttons instead of a list of toggles.
Here is what I want it to look like : http://gph.is/2zHDgdY
For the context: I'm trying to make an inventory system where each items are prefabs and have a different list of options. For example, the item "Wood" has Burn, Drop and Cancel, while the item "Berries" has Consume, Cook, Drop and Cancel.
Usually, the standard dropdown seems to use toggles because it assumes there would be a sort of "Submit" button, but I would like and effect to be triggered as soon as the user clicks a certain option. However, when I try to change the options elements to have a Button component instead of a Toggle component, I get the error "The dropdown template is not valid. The template must have a child GameObject with a Toggle component serving as the item.".
Thanks
Answer by Larry-Dietz · Dec 28, 2017 at 10:25 PM
I don't think you can use buttons unless you roll your own dropdown component.
However, you can simulate it pretty easy.
In the Template, disable the Item Checkmark's Image componant, and replacing the Item Background image component's sprite with your button sprite. If your button already has the text for the button in the sprite, you can also disable the Text component in Item Label.
Your code will still have to check for which toggle is on, but the look and feel should be that of a button.
You can also disable the Text component of Label and and Image component of Arrow in the base of the DropDown, and change the DropDown image component to a button image to be clicked to access the DropDown, instead of displaying the text of the selected drop down item.
I know it isn't what you are looking for, but it is a quick easy way to get the appearance you want.
Hope this helps, -Larry
Hey thanks Larry,
That's what I tried actually and at the end of the day my best bet is probably gonna be, like you said, to mke my own dropdown.
$$anonymous$$y first thoigh would be to either instantiate a prefab of the options list or use a SetActive to make the options list appear.
Would you know what the simplest way is for making a dropdown menu kind of "appears gradually"? With Instantiate and SetActive, the game object would just instantaneously appear, but I don't know how to make it appear fluidly.
$$anonymous$$aybe an instantiate with a low alpha an lerp the alpha to the full?
Sorry if my terms aren't right i'm suuuuper newb!
I just pulled the source code for the DropDown.cs to see exactly what they were doing with the default DropDown.
Looks like they are just doing a tween on the alpha.
If you want to take a look at the source for the default dropdown to get some ideas on rolling your own, take a look at https://bitbucket.org/Unity-Technologies/ui/src/0bd08e22bc17bdf80bf7b997a4b43877ae4ee9ac/UnityEngine.UI/UI/Core/Dropdown.cs?at=5.2&fileviewer=file-view-default
It should give you a big leg up on writing one custom to use buttons.
Hope it helps, -Larry
Your answer
![](https://koobas.hobune.stream/wayback/20220612145413im_/https://answers.unity.com/themes/thub/images/avi.jpg)