AddNodeItemsToMenu() public static method

public static AddNodeItemsToMenu ( GenericMenu menu, GenericMenu callback ) : void
menu UnityEditor.GenericMenu
callback UnityEditor.GenericMenu
return void
Example #1
0
        void ShowCustomContextMenu()
        {
            // Only cares about single right click.
            if (Event.current.type != EventType.MouseDown)
            {
                return;
            }
            if (Event.current.button != 1)
            {
                return;
            }
            if (Event.current.clickCount != 1)
            {
                return;
            }

            // Consume this mouse event.
            Event.current.Use();

            // Record the current mouse position
            m_contextMenuMouseDownPosition = Event.current.mousePosition;

            // Build a context menu.
            var menu = new GenericMenu();

            if (selection.Count != 0)
            {
                // Node operations
                menu.AddItem(new GUIContent("Cut"), false, ContextMenuCallback, "Cut");
                menu.AddItem(new GUIContent("Copy"), false, ContextMenuCallback, "Copy");
                menu.AddItem(new GUIContent("Duplicate"), false, ContextMenuCallback, "Duplicate");
                menu.AddSeparator("");
                menu.AddItem(new GUIContent("Delete"), false, ContextMenuCallback, "Delete");
                menu.AddSeparator("");
                var colors = Enum.GetValues(typeof(Graphs.Styles.Color)).Cast <Graphs.Styles.Color>().Distinct();
                foreach (var color in colors)
                {
                    menu.AddItem(new GUIContent("Color/" + color), false, ContextMenuColorCallback, color);
                }
            }
            else if (edgeGUI.edgeSelection.Count != 0)
            {
                // Edge operations
                menu.AddItem(new GUIContent("Delete"), false, ContextMenuCallback, "Delete");
            }
            else
            {
                // Clicked on empty space.
                menu.AddItem(new GUIContent("Paste"), false, ContextMenuCallback, "Paste");
            }

            // "Create" menu
            menu.AddSeparator("");
            NodeFactory.AddNodeItemsToMenu(menu, CreateMenuItemCallback);

            menu.ShowAsContext();
        }
Example #2
0
        void ShowCustomContextMenu()
        {
            // Only cares about single right click.
            if (Event.current.type != EventType.MouseDown)
            {
                return;
            }
            if (Event.current.button != 1)
            {
                return;
            }
            if (Event.current.clickCount != 1)
            {
                return;
            }

            // Consume this mouse event.
            Event.current.Use();


            // Build a context menu.
            var menu = new GenericMenu();

            if (selection.Count != 0)
            {
                // Block operations
                menu.AddItem(new GUIContent("Cut"), false, ContextMenuCallback, "Cut");
                menu.AddItem(new GUIContent("Copy"), false, ContextMenuCallback, "Copy");
                menu.AddItem(new GUIContent("Duplicate"), false, ContextMenuCallback, "Duplicate");
                if (selection.Count > 1)
                {
                    menu.AddItem(new GUIContent("Group"), false, ContextMenuCallback, "Group");
                }
                menu.AddSeparator("");
                menu.AddItem(new GUIContent("Delete"), false, ContextMenuCallback, "Delete");
            }
            else if (edgeGUI.edgeSelection.Count != 0)
            {
                // Edge operations
                menu.AddItem(new GUIContent("Delete"), false, ContextMenuCallback, "Delete");
            }
            else
            {
                // Clicked on empty space.
                menu.AddItem(new GUIContent("Paste"), false, ContextMenuCallback, "Paste");
            }


            // "Create" menu
            menu.AddSeparator("");
            NodeFactory.AddNodeItemsToMenu(menu, CreateMenuItemCallback);

            menu.ShowAsContext();
        }