Class TMP_Dropdown
Implements
Inherited Members
Namespace: TMPro
Assembly: Unity.TextMeshPro.dll
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
IsExpanded
Declaration
public bool IsExpanded { get; }
Property Value
Type | Description |
---|---|
bool |
alphaFadeSpeed
The time interval at which a drop down will appear and disappear
Declaration
public float alphaFadeSpeed { get; set; }
Property Value
Type | Description |
---|---|
float |
captionImage
The Image component to hold the image of the currently selected option.
Declaration
public Image captionImage { get; set; }
Property Value
Type | Description |
---|---|
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 |
itemImage
The Image component to hold the image of the item
Declaration
public Image itemImage { get; set; }
Property Value
Type | Description |
---|---|
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 |
---|---|
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 |
---|---|
int |
Methods
AddOptions(List<string>)
Declaration
public void AddOptions(List<string> options)
Parameters
Type | Name | Description |
---|---|---|
List<string> | options |
AddOptions(List<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
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(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(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 |
---|---|---|
BaseEventData | eventData | The associated event data. |
Remarks
Called by a BaseInputModule when a Cancel event occurs.
OnDisable()
Declaration
protected override void OnDisable()
Overrides
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 |
---|---|---|
PointerEventData | eventData | The associated event data. |
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 |
---|---|---|
BaseEventData | eventData | The associated event data. |
OnValidate()
Declaration
protected override void OnValidate()
Overrides
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(int)
Set index number of the current selection in the Dropdown without invoking onValueChanged callback.
Declaration
public void SetValueWithoutNotify(int input)
Parameters
Type | Name | Description |
---|---|---|
int | 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()