Class GenericDropdownMenu
GenericDropdownMenu allows you to display contextual menus with default textual options or any VisualElement.
Namespace: UnityEngine.UIElements
Syntax
public class GenericDropdownMenu : object, IGenericMenu
Constructors
GenericDropdownMenu()
Initializes and returns an instance of GenericDropdownMenu.
Declaration
public GenericDropdownMenu()
Fields
checkmarkUssClassName
USS class name of separators in elements of this type.
Declaration
public static readonly string checkmarkUssClassName
Field Value
Type | Description |
---|---|
String |
containerInnerUssClassName
USS class name of inner containers in elements of this type.
Declaration
public static readonly string containerInnerUssClassName
Field Value
Type | Description |
---|---|
String |
containerOuterUssClassName
USS class name of outer containers in elements of this type.
Declaration
public static readonly string containerOuterUssClassName
Field Value
Type | Description |
---|---|
String |
itemUssClassName
USS class name of labels in elements of this type.
Declaration
public static readonly string itemUssClassName
Field Value
Type | Description |
---|---|
String |
labelUssClassName
USS class name of labels in elements of this type.
Declaration
public static readonly string labelUssClassName
Field Value
Type | Description |
---|---|
String |
separatorUssClassName
USS class name of separators in elements of this type.
Declaration
public static readonly string separatorUssClassName
Field Value
Type | Description |
---|---|
String |
ussClassName
USS class name of elements of this type.
Declaration
public static readonly string ussClassName
Field Value
Type | Description |
---|---|
String |
Properties
contentContainer
Returns the content container for the GenericDropdownMenu. Allows users to create their own dropdown menu if they don't want to use the default implementation.
Declaration
public VisualElement contentContainer { get; }
Property Value
Type | Description |
---|---|
VisualElement |
Methods
AddDisabledItem(String, Boolean)
Adds a disabled item to this menu using a default VisualElement.
Declaration
public void AddDisabledItem(string itemName, bool isChecked)
Parameters
Type | Name | Description |
---|---|---|
String | itemName | The text to display to the user. |
Boolean | isChecked | Indicates whether a checkmark next to the item is displayed. |
Remarks
Items added with this method cannot be selected by the user.
AddItem(String, Boolean, Action)
Adds an item to this menu using a default VisualElement.
Declaration
public void AddItem(string itemName, bool isChecked, Action action)
Parameters
Type | Name | Description |
---|---|---|
String | itemName | The text to display to the user. |
Boolean | isChecked | Indicates whether a checkmark next to the item is displayed. |
Action | action | The callback to invoke when the item is selected by the user. |
AddItem(String, Boolean, Action<Object>, Object)
Adds an item to this menu using a default VisualElement.
Declaration
public void AddItem(string itemName, bool isChecked, Action<object> action, object data)
Parameters
Type | Name | Description |
---|---|---|
String | itemName | The text to display to the user. |
Boolean | isChecked | Indicates whether a checkmark next to the item is displayed. |
Action<Object> | action | The callback to invoke when the item is selected by the user. |
Object | data | The object to pass to the callback as a parameter. |
Remarks
This overload of the method accepts an arbitrary object that's passed as a parameter to your callback.
AddSeparator(String)
Adds a visual separator after the previously added items in this menu.
Declaration
public void AddSeparator(string path)
Parameters
Type | Name | Description |
---|---|---|
String | path | Not used. |
DropDown(Rect, VisualElement, Boolean)
Displays the menu at the specified position.
Declaration
public void DropDown(Rect position, VisualElement targetElement = null, bool anchored = false)
Parameters
Type | Name | Description |
---|---|---|
Rect | position | The position in the coordinate space of the panel. |
VisualElement | targetElement | The element used to determine in which root to parent the menu. |
Boolean | anchored | Whether the menu should use the width of the position argument instead of its normal width. |
Remarks
This method automatically finds the parent VisualElement that displays the menu.
For editor UI,