Ejemplo n.º 1
0
        void ConvertToProperty(ContextualMenu.MenuAction action)
        {
            var selectedNodeViews = selection.OfType <NodeView>().Select(x => x.node).ToList();

            foreach (var node in selectedNodeViews)
            {
                if (!(node is IPropertyFromNode))
                {
                    continue;
                }

                var converter = node as IPropertyFromNode;
                var prop      = converter.AsNodeProperty();
                graph.AddShaderProperty(prop);

                var propNode = new PropertyNode();
                propNode.drawState = node.drawState;
                graph.AddNode(propNode);
                propNode.propertyGuid = prop.guid;

                var oldSlot = node.FindSlot <NodeSlot>(converter.outputSlotId);
                var newSlot = propNode.FindSlot <NodeSlot>(PropertyNode.OutputSlotId);

                foreach (var edge in graph.GetEdges(oldSlot.slotReference))
                {
                    graph.Connect(newSlot.slotReference, edge.inputSlot);
                }

                graph.RemoveNode(node);
            }
        }
Ejemplo n.º 2
0
 ContextualMenu.MenuAction.StatusFlags SeeDocumentationStatus(ContextualMenu.MenuAction action)
 {
     if (selection.OfType <NodeView>().First().node.documentationURL == null)
     {
         return(ContextualMenu.MenuAction.StatusFlags.Disabled);
     }
     return(ContextualMenu.MenuAction.StatusFlags.Normal);
 }
Ejemplo n.º 3
0
        void SeeDocumentation(ContextualMenu.MenuAction action)
        {
            var node = selection.OfType <NodeView>().First().node;

            if (node.documentationURL != null)
            {
                System.Diagnostics.Process.Start(node.documentationURL);
            }
        }
Ejemplo n.º 4
0
 ContextualMenu.MenuAction.StatusFlags ConvertToPropertyStatus(ContextualMenu.MenuAction action)
 {
     if (selection.OfType <NodeView>().Any(v => v.node != null))
     {
         if (selection.OfType <NodeView>().Any(v => v.node is IPropertyFromNode))
         {
             return(ContextualMenu.MenuAction.StatusFlags.Normal);
         }
         return(ContextualMenu.MenuAction.StatusFlags.Disabled);
     }
     return(ContextualMenu.MenuAction.StatusFlags.Hidden);
 }
Ejemplo n.º 5
0
        void DisconnectAll(ContextualMenu.MenuAction a)
        {
            HashSet <GraphElement> toDelete = new HashSet <GraphElement>();

            AddConnectionsToDeleteSet(inputContainer, ref toDelete);
            AddConnectionsToDeleteSet(outputContainer, ref toDelete);
            toDelete.Remove(null);

            GraphView graphView = GetFirstAncestorOfType <GraphView>();

            if (graphView != null)
            {
                graphView.DeleteElements(toDelete);
            }
            else
            {
                Debug.Log("Disconnecting nodes that are not in a GraphView will not work.");
            }
        }
Ejemplo n.º 6
0
        protected override void DoDisplayMenu(ContextualMenu menu, EventBase triggerEvent)
        {
            GenericMenu genericMenu = new GenericMenu();

            foreach (ContextualMenu.MenuItem current in menu.MenuItems())
            {
                ContextualMenu.MenuAction action = current as ContextualMenu.MenuAction;
                if (action != null)
                {
                    if ((action.status & ContextualMenu.MenuAction.StatusFlags.Hidden) != ContextualMenu.MenuAction.StatusFlags.Hidden)
                    {
                        bool on = (action.status & ContextualMenu.MenuAction.StatusFlags.Checked) == ContextualMenu.MenuAction.StatusFlags.Checked;
                        if ((action.status & ContextualMenu.MenuAction.StatusFlags.Disabled) == ContextualMenu.MenuAction.StatusFlags.Disabled)
                        {
                            genericMenu.AddDisabledItem(new GUIContent(action.name));
                        }
                        else
                        {
                            genericMenu.AddItem(new GUIContent(action.name), on, delegate
                            {
                                action.Execute(triggerEvent);
                            });
                        }
                    }
                }
                else
                {
                    genericMenu.AddSeparator(string.Empty);
                }
            }
            Vector2 position = Vector2.zero;

            if (triggerEvent is IMouseEvent)
            {
                position = ((IMouseEvent)triggerEvent).mousePosition;
            }
            else if (triggerEvent.target is VisualElement)
            {
                position = ((VisualElement)triggerEvent.target).layout.center;
            }
            genericMenu.DropDown(new Rect(position, Vector2.zero));
        }
Ejemplo n.º 7
0
        ContextualMenu.MenuAction.StatusFlags DisconnectAllStatus(ContextualMenu.MenuAction a)
        {
            VisualElement[] containers =
            {
                inputContainer, outputContainer
            };

            foreach (var container in containers)
            {
                var currentInputs = container.Query <Port>().ToList();
                foreach (var elem in currentInputs)
                {
                    if (elem.connected)
                    {
                        return(ContextualMenu.MenuAction.StatusFlags.Normal);
                    }
                }
            }

            return(ContextualMenu.MenuAction.StatusFlags.Disabled);
        }
Ejemplo n.º 8
0
 void OnContextMenuNodeCreate(ContextualMenu.MenuAction a)
 {
     RequestNodeCreation(null, -1, a.eventInfo.mousePosition);
 }
Ejemplo n.º 9
0
 void ToggleAnchorState(ContextualMenu.MenuAction a)
 {
     anchored = !anchored;
 }