How to create a dynamic selectable list on an object in Unity?

Asked

Viewed 78 times

0

I would like to create a list that would appear when the user clicks a button. The list would show the information contained in the database, and the user would select which one would give continuity to the game according to the selected option. Can anyone help me with that? You do not need to have any type of image, I would like to make a very simple list even if it only had 1 or 2 columns, being the first with the name "Id" and the second with the name "Theme", the user selects the desired row and I use the id corresponding to the selected theme. If possible, I wanted to do this in a kind of "pop-up" that after having the theme selected, would disappear, returning to appear again only if the button was clicked again.

2 answers

0


I implemented a minimal example here that can give you some ideas:

Exemplo mínimo

The list itself is made with the UI > Scroll View, has a nice tutorial here.

That’s the hierarchy of the scene:

Hierarquia

I created two animations for Scroll View, one In and another Out. They only mess with the height of the Scroll View, from the center, but you can do any animation (alpha, color, position, etc). So I created a component Animator within the Scroll View, who organizes these animations like this:

Animator

The state Open has nothing. The state Closed has the animation In frozen in the first frame (speed = 0). Trigger In active the transition Any State -> In. The Trigger Out active the transition Open -> Out.

If you’re not used to the Animator, have several tutorials scattered around. What is missing is just call these triggers by the script:

public void OpenMenu()
{
    scroll.GetComponent<Animator>().SetTrigger("In");
}

public void CloseMenu()
{
    scroll.GetComponent<Animator>().SetTrigger("Out");
} 

Remembering that this is just the description of a technique, not the solution, has to refine enough to put into production. I hope it helps!

  • Thanks for the answer! what I wanted, in fact, is a way to create a table that shows the elements contained in the database according to the user’s search, and when the user selects, the table "closes" and this continuity the application, with the element selected by the user.

  • 1

    Then, you can use this technique and popular the table with the database items on OpenMenu. Create a Prefab of your item, and when you open the list you use the Instantiate to create multiple items within the Content of Scroll View, changing the text to the values of the DB.

  • All right, I’ll try to do it this way so, thanks!

  • Hey, man, what’s up? I want to do another business in the project and I would like to use as a basis this solution you provided me, I know it’s asking too much, but how do you put the step by step how to do this process? I wanted to do it exactly the way you did it in the solution. I looked for some videos of how to use the Animator but most is teaching to move objects that are already apparent in the UI, I did not find any that when clicking a button, the scrollview appeared in front, like you did

0

Its description partially matches that of a combobox, I recommend that you see the "Dropdown" element of the unity3D UI:

Dropdown | Unity UI | 1.0.0

  • I came to take a look at the dropdown, but the intention is to have at least 10 options for the user to choose. I believe that doing using dropdown would be with an unpleasant and/or messy "appearance"

Browser other questions tagged

You are not signed in. Login or sign up in order to post.