Class ElementAdderMenuCommandAttribute
Annotate IElementAdderMenuCommand<TContext> implementations with a ElementAdderMenuCommandAttribute to associate it with the contract type of addable elements.
Namespace: Unity.VisualScripting.ReorderableList.Element_Adder_Menu
Syntax
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true, Inherited = false)]
public sealed class ElementAdderMenuCommandAttribute : Attribute, _Attribute
Examples
The following source code demonstrates how to add a helper menu command to the add element menu of a shopping list:
[ElementAdderMenuCommand(typeof(ShoppingItem))]
public class AddFavoriteShoppingItemsCommand : IElementAdderMenuCommand<ShoppingList> {
public AddFavoriteShoppingItemsCommand() {
Content = new GUIContent("Add Favorite Items");
}
public GUIContent Content { get; private set; }
public bool CanExecute(IElementAdder<ShoppingList> elementAdder) {
return true;
}
public void Execute(IElementAdder<ShoppingList> elementAdder) {
// xTODO: Add favorite items to the shopping list!
}
}
@ElementAdderMenuCommand(ShoppingItem)
class AddFavoriteShoppingItemsCommand extends IElementAdderMenuCommand.<ShoppingList> {
var _content:GUIContent = new GUIContent('Add Favorite Items');
function get Content():GUIContent { return _content; }
function CanExecute(elementAdder:IElementAdder.<ShoppingList>):boolean {
return true;
}
function Execute(elementAdder:IElementAdder.<ShoppingList>) {
// xTODO: Add favorite items to the shopping list!
}
}
Constructors
ElementAdderMenuCommandAttribute(Type)
Initializes a new instance of the ElementAdderMenuCommandAttribute class.
Declaration
public ElementAdderMenuCommandAttribute(Type contractType)
Parameters
Type | Name | Description |
---|---|---|
Type | contractType | Contract type of addable elements. |
Properties
ContractType
Gets the contract type of addable elements.
Declaration
public Type ContractType { get; }
Property Value
Type | Description |
---|---|
Type |