docs.unity3d.com
    Show / Hide Table of Contents

    Class TMP_Dropdown

    Inheritance
    Object
    UnityEngine.EventSystems.UIBehaviour
    UnityEngine.UI.Selectable
    TMP_Dropdown
    Inherited Members
    UnityEngine.UI.Selectable.s_Selectables
    UnityEngine.UI.Selectable.s_SelectableCount
    UnityEngine.UI.Selectable.m_CurrentIndex
    UnityEngine.UI.Selectable.AllSelectablesNoAlloc(UnityEngine.UI.Selectable[])
    UnityEngine.UI.Selectable.OnCanvasGroupChanged()
    UnityEngine.UI.Selectable.IsInteractable()
    UnityEngine.UI.Selectable.OnDidApplyAnimationProperties()
    UnityEngine.UI.Selectable.OnEnable()
    UnityEngine.UI.Selectable.OnTransformParentChanged()
    UnityEngine.UI.Selectable.OnValidate()
    UnityEngine.UI.Selectable.Reset()
    UnityEngine.UI.Selectable.InstantClearState()
    UnityEngine.UI.Selectable.DoStateTransition(UnityEngine.UI.Selectable.SelectionState, System.Boolean)
    UnityEngine.UI.Selectable.FindSelectable(UnityEngine.Vector3)
    UnityEngine.UI.Selectable.FindSelectableOnLeft()
    UnityEngine.UI.Selectable.FindSelectableOnRight()
    UnityEngine.UI.Selectable.FindSelectableOnUp()
    UnityEngine.UI.Selectable.FindSelectableOnDown()
    UnityEngine.UI.Selectable.OnMove(UnityEngine.EventSystems.AxisEventData)
    UnityEngine.UI.Selectable.IsHighlighted()
    UnityEngine.UI.Selectable.IsPressed()
    UnityEngine.UI.Selectable.OnPointerDown(UnityEngine.EventSystems.PointerEventData)
    UnityEngine.UI.Selectable.OnPointerUp(UnityEngine.EventSystems.PointerEventData)
    UnityEngine.UI.Selectable.OnPointerEnter(UnityEngine.EventSystems.PointerEventData)
    UnityEngine.UI.Selectable.OnPointerExit(UnityEngine.EventSystems.PointerEventData)
    UnityEngine.UI.Selectable.OnSelect(UnityEngine.EventSystems.BaseEventData)
    UnityEngine.UI.Selectable.OnDeselect(UnityEngine.EventSystems.BaseEventData)
    UnityEngine.UI.Selectable.Select()
    UnityEngine.UI.Selectable.allSelectablesArray
    UnityEngine.UI.Selectable.allSelectableCount
    UnityEngine.UI.Selectable.allSelectables
    UnityEngine.UI.Selectable.navigation
    UnityEngine.UI.Selectable.transition
    UnityEngine.UI.Selectable.colors
    UnityEngine.UI.Selectable.spriteState
    UnityEngine.UI.Selectable.animationTriggers
    UnityEngine.UI.Selectable.targetGraphic
    UnityEngine.UI.Selectable.interactable
    UnityEngine.UI.Selectable.image
    UnityEngine.UI.Selectable.animator
    UnityEngine.UI.Selectable.currentSelectionState
    UnityEngine.EventSystems.UIBehaviour.OnDestroy()
    UnityEngine.EventSystems.UIBehaviour.IsActive()
    UnityEngine.EventSystems.UIBehaviour.OnRectTransformDimensionsChange()
    UnityEngine.EventSystems.UIBehaviour.OnBeforeTransformParentChanged()
    UnityEngine.EventSystems.UIBehaviour.OnCanvasHierarchyChanged()
    UnityEngine.EventSystems.UIBehaviour.IsDestroyed()
    Namespace: TMPro
    Syntax
    [AddComponentMenu("UI/Dropdown - TextMeshPro", 35)]
    [RequireComponent(typeof(RectTransform))]
    public class TMP_Dropdown : Selectable, IMoveHandler, IPointerDownHandler, IPointerUpHandler, IPointerEnterHandler, IPointerExitHandler, ISelectHandler, IDeselectHandler, IPointerClickHandler, ISubmitHandler, ICancelHandler, IEventSystemHandler

    Constructors

    TMP_Dropdown()

    Declaration
    protected TMP_Dropdown()

    Properties

    alphaFadeSpeed

    The time interval at which a drop down will appear and disappear

    Declaration
    public float alphaFadeSpeed { get; set; }
    Property Value
    Type Description
    Single

    captionImage

    The Image component to hold the image of the currently selected option.

    Declaration
    public Image captionImage { get; set; }
    Property Value
    Type Description
    UnityEngine.UI.Image

    captionText

    The Text component to hold the text of the currently selected option.

    Declaration
    public TMP_Text captionText { get; set; }
    Property Value
    Type Description
    TMP_Text

    IsExpanded

    Declaration
    public bool IsExpanded { get; }
    Property Value
    Type Description
    Boolean

    itemImage

    The Image component to hold the image of the item

    Declaration
    public Image itemImage { get; set; }
    Property Value
    Type Description
    UnityEngine.UI.Image

    itemText

    The Text component to hold the text of the item.

    Declaration
    public TMP_Text itemText { get; set; }
    Property Value
    Type Description
    TMP_Text

    onValueChanged

    Declaration
    public TMP_Dropdown.DropdownEvent onValueChanged { get; set; }
    Property Value
    Type Description
    TMP_Dropdown.DropdownEvent

    options

    Declaration
    public List<TMP_Dropdown.OptionData> options { get; set; }
    Property Value
    Type Description
    List<TMP_Dropdown.OptionData>

    placeholder

    The placeholder Graphic component. Shown when no option is selected.

    Declaration
    public Graphic placeholder { get; set; }
    Property Value
    Type Description
    UnityEngine.UI.Graphic

    template

    The Rect Transform of the template for the dropdown list.

    Declaration
    public RectTransform template { get; set; }
    Property Value
    Type Description
    RectTransform

    value

    Declaration
    public int value { get; set; }
    Property Value
    Type Description
    Int32

    Methods

    AddOptions(List<String>)

    Declaration
    public void AddOptions(List<string> options)
    Parameters
    Type Name Description
    List<String> options

    AddOptions(List<TMP_Dropdown.OptionData>)

    Declaration
    public void AddOptions(List<TMP_Dropdown.OptionData> options)
    Parameters
    Type Name Description
    List<TMP_Dropdown.OptionData> options

    AddOptions(List<Sprite>)

    Declaration
    public void AddOptions(List<Sprite> options)
    Parameters
    Type Name Description
    List<Sprite> options

    Awake()

    Declaration
    protected override void Awake()
    Overrides
    UnityEngine.UI.Selectable.Awake()

    ClearOptions()

    Clear the list of options in the Dropdown.

    Declaration
    public void ClearOptions()

    CreateBlocker(Canvas)

    Create a blocker that blocks clicks to other controls while the dropdown list is open.

    Declaration
    protected virtual GameObject CreateBlocker(Canvas rootCanvas)
    Parameters
    Type Name Description
    Canvas rootCanvas

    The root canvas the dropdown is under.

    Returns
    Type Description
    GameObject

    The created blocker object

    Remarks

    Override this method to implement a different way to obtain a blocker GameObject.

    CreateDropdownList(GameObject)

    Create the dropdown list to be shown when the dropdown is clicked. The dropdown list should correspond to the provided template GameObject, equivalent to instantiating a copy of it.

    Declaration
    protected virtual GameObject CreateDropdownList(GameObject template)
    Parameters
    Type Name Description
    GameObject template

    The template to create the dropdown list from.

    Returns
    Type Description
    GameObject

    The created drop down list gameobject.

    Remarks

    Override this method to implement a different way to obtain a dropdown list GameObject.

    CreateItem(TMP_Dropdown.DropdownItem)

    Create a dropdown item based upon the item template.

    Declaration
    protected virtual TMP_Dropdown.DropdownItem CreateItem(TMP_Dropdown.DropdownItem itemTemplate)
    Parameters
    Type Name Description
    TMP_Dropdown.DropdownItem itemTemplate

    e template to create the option item from.

    Returns
    Type Description
    TMP_Dropdown.DropdownItem

    The created dropdown item component

    Remarks

    Override this method to implement a different way to obtain an option item. The option item should correspond to the provided template DropdownItem and its GameObject, equivalent to instantiating a copy of it.

    DestroyBlocker(GameObject)

    Convenience method to explicitly destroy the previously generated blocker object

    Declaration
    protected virtual void DestroyBlocker(GameObject blocker)
    Parameters
    Type Name Description
    GameObject blocker

    The blocker object to destroy.

    Remarks

    Override this method to implement a different way to dispose of a blocker GameObject that blocks clicks to other controls while the dropdown list is open.

    DestroyDropdownList(GameObject)

    Convenience method to explicitly destroy the previously generated dropdown list

    Declaration
    protected virtual void DestroyDropdownList(GameObject dropdownList)
    Parameters
    Type Name Description
    GameObject dropdownList

    The dropdown list GameObject to destroy

    Remarks

    Override this method to implement a different way to dispose of a dropdown list GameObject.

    DestroyItem(TMP_Dropdown.DropdownItem)

    Convenience method to explicitly destroy the previously generated Items.

    Declaration
    protected virtual void DestroyItem(TMP_Dropdown.DropdownItem item)
    Parameters
    Type Name Description
    TMP_Dropdown.DropdownItem item

    The Item to destroy.

    Remarks

    Override this method to implement a different way to dispose of an option item. Likely no action needed since destroying the dropdown list destroys all contained items as well.

    Hide()

    Hide the dropdown list. I.e. close it.

    Declaration
    public void Hide()

    OnCancel(BaseEventData)

    This will hide the dropdown list.

    Declaration
    public virtual void OnCancel(BaseEventData eventData)
    Parameters
    Type Name Description
    UnityEngine.EventSystems.BaseEventData eventData

    The associated event data.

    Implements
    UnityEngine.EventSystems.ICancelHandler.OnCancel(UnityEngine.EventSystems.BaseEventData)
    Remarks

    Called by a BaseInputModule when a Cancel event occurs.

    OnDisable()

    Declaration
    protected override void OnDisable()
    Overrides
    UnityEngine.UI.Selectable.OnDisable()

    OnPointerClick(PointerEventData)

    Handling for when the dropdown is initially 'clicked'. Typically shows the dropdown

    Declaration
    public virtual void OnPointerClick(PointerEventData eventData)
    Parameters
    Type Name Description
    UnityEngine.EventSystems.PointerEventData eventData

    The associated event data.

    Implements
    UnityEngine.EventSystems.IPointerClickHandler.OnPointerClick(UnityEngine.EventSystems.PointerEventData)

    OnSubmit(BaseEventData)

    Handling for when the dropdown is selected and a submit event is processed. Typically shows the dropdown

    Declaration
    public virtual void OnSubmit(BaseEventData eventData)
    Parameters
    Type Name Description
    UnityEngine.EventSystems.BaseEventData eventData

    The associated event data.

    Implements
    UnityEngine.EventSystems.ISubmitHandler.OnSubmit(UnityEngine.EventSystems.BaseEventData)

    RefreshShownValue()

    Refreshes the text and image (if available) of the currently selected option.

    Declaration
    public void RefreshShownValue()
    Remarks

    If you have modified the list of options, you should call this method afterwards to ensure that the visual state of the dropdown corresponds to the updated options.

    SetValueWithoutNotify(Int32)

    Set index number of the current selection in the Dropdown without invoking onValueChanged callback.

    Declaration
    public void SetValueWithoutNotify(int input)
    Parameters
    Type Name Description
    Int32 input

    The new index for the current selection.

    Show()

    Show the dropdown.

    Plan for dropdown scrolling to ensure dropdown is contained within screen.

    We assume the Canvas is the screen that the dropdown must be kept inside. This is always valid for screen space canvas modes. For world space canvases we don't know how it's used, but it could be e.g. for an in-game monitor. We consider it a fair constraint that the canvas must be big enough to contain dropdowns.

    Declaration
    public void Show()

    Start()

    Declaration
    protected override void Start()
    Overrides
    UnityEngine.EventSystems.UIBehaviour.Start()
    Back to top
    Copyright © 2023 Unity Technologies — Terms of use
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    Generated by DocFX on 18 October 2023