Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections.Generic;
- using UnityEditor;
- public class ContextMenuItem
- {
- // The name that will be displayed to the user
- public string Name { get; set; }
- // The method that will be called when the menu item is clicked
- public GenericMenu.MenuFunction Callback { get; }
- // Does this menu item have children
- public bool IsParent { get; }
- // Is this menu item part of a sub menu
- public bool IsChild { get; }
- // If this a parent menu item, this holds the children
- public List<ContextMenuItem> ChildItems { get; set; }
- // Show the children of this parent menu item
- public bool ShowChildren { get; set; }
- // If this is a child menu item, store the parents name
- public string ParentName { get; set; }
- /// <summary>
- /// Creates a menu item with just a name
- /// </summary>
- /// <param name="name">The name that will be displayed</param>
- public ContextMenuItem(string name) :
- this(name, null, false, false, "")
- {
- }
- /// <summary>
- /// Creates a menu item that performs an action
- /// </summary>
- /// <param name="name">The name that will be displayed</param>
- /// <param name="callback">The action that is performed when clicked</param>
- public ContextMenuItem(string name, GenericMenu.MenuFunction callback) :
- this(name, callback, false, false, "")
- {
- }
- /// <summary>
- /// Creates a menu item as a parent
- /// </summary>
- /// <param name="name">The name that will be displayed</param>
- /// <param name="callback">The action that is performed when clicked</param>
- /// <param name="isParent">Specifies if this is a parent menu</param>
- public ContextMenuItem(string name, GenericMenu.MenuFunction callback, bool isParent) :
- this(name, callback, isParent, false, "")
- {
- }
- /// <summary>
- /// Creates a menu item a s a child
- /// </summary>
- /// <param name="name">The name that will be displayed</param>
- /// <param name="callback">The action that is performed when clicked</param>
- /// <param name="isParent">Specifies if this is a parent menu item</param>
- /// <param name="isChild">Specifies if this is a child menu item</param>
- /// <param name="parentName">The name of the parent the child belongs to</param>
- public ContextMenuItem(string name, GenericMenu.MenuFunction callback, bool isParent, bool isChild, string parentName)
- {
- Name = name;
- Callback = callback;
- IsParent = isParent;
- if(IsParent)
- ChildItems = new List<ContextMenuItem>();
- IsChild = isChild;
- ParentName = parentName;
- }
- /// <summary>
- /// Add a child menu item
- /// </summary>
- /// <param name="child">The child to add</param>
- public void AddChild(ContextMenuItem child)
- {
- ChildItems.Add(child);
- }
- /// <summary>
- /// Perform the menu items action
- /// </summary>
- public void Execute()
- {
- Callback?.Invoke();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement