Search Unity

Question Custom DropDown<SomeType> using UI Toolkit

Discussion in 'UI Toolkit' started by Davon92, Apr 27, 2023.

  1. Davon92


    Oct 24, 2014
    Hello. Very straight forward question no gotchas. this is for a custom inspector in the editor.
    I Have 1 File, Class A,

    Class A Contains 3 Properties.
    A user provided List of AnimClips
    A user provided List of AudioClips
    A List of Struct B

    Struct B Contains
    An AudioClip Field
    An AnimClip Field
    An int Field

    For O(n) of Struct B List.
    I would like to have the editor User select
    1 Audio Clip and 1 Anim Clip from a popup or dropdown using data they provided to Class A Anim Clips and Class A Audio Clips variables.

    All list are dynamic and can be 0(n) items.

    How can i best use UI Toolkit to achieve this? As i have been struggling for the past few days.
  2. huwp


    May 22, 2013
    The source data for the DropDown may be the names taken from the asset list.

    dropDown.choices = AssetList.Select(i =>;

    When the user performs a selection from the dropdown, refer to the selected index to retrieve the chosen asset.

    var selectedAsset = AssetList[dropDown.index];
  3. Davon92


    Oct 24, 2014
    ah so this is something I understand as I have done something similar with the popup for UIToolkit.
    Is it possible to assign this DropDown or PopUp to Class/StructB?

    Most of my trouble comes from the fact that i want to have a list of Class/Struct B. which means I would need dropdowns/popups inside Class B. but the data to fill those dropdowns come from Class A Which Has Class B as a variable.