ElementAdderMenuBuilder Class |
Namespace: Rotorz.ReorderableList
public static class ElementAdderMenuBuilder
Name | Description | |
---|---|---|
![]() ![]() | ForTContext |
Gets a IElementAdderMenuBuilderTContext to build an element
adder menu for a context object of the type TContext.
|
![]() ![]() | ForTContext(Type) |
Gets a IElementAdderMenuBuilderTContext to build an element
adder menu for a context object of the type TContext.
|
The following example demonstrates how to build and display a menu which allows the user to add elements to a given context object upon clicking a button:
public class ShoppingListElementAdder : IElementAdder<ShoppingList> { public ShoppingListElementAdder(ShoppingList shoppingList) { Object = shoppingList; } public ShoppingList Object { get; private set; } public bool CanAddElement(Type type) { return true; } public object AddElement(Type type) { var instance = Activator.CreateInstance(type); shoppingList.Add((ShoppingItem)instance); return instance; } } private void DrawAddMenuButton(ShoppingList shoppingList) { var content = new GUIContent("Add Menu"); Rect position = GUILayoutUtility.GetRect(content, GUI.skin.button); if (GUI.Button(position, content)) { var builder = ElementAdderMenuBuilder.For<ShoppingList>(ShoppingItem); builder.SetElementAdder(new ShoppingListElementAdder(shoppingList)); var menu = builder.GetMenu(); menu.DropDown(buttonPosition); } }