Пример #1
0
        public void RemovePort(PortView p)
        {
            // Remove all connected edges:
            var edgesCopy = p.GetEdges().ToList();

            foreach (var e in edgesCopy)
            {
                owner.Disconnect(e, refreshPorts: false);
            }

            if (p.direction == Direction.Input)
            {
                inputPortViews.Remove(p);
                inputContainer.Remove(p);
            }
            else
            {
                outputPortViews.Remove(p);
                outputContainer.Remove(p);
            }

            List <PortView> ports;

            portsPerFieldName.TryGetValue(p.fieldName, out ports);
            ports.Remove(p);
        }
Пример #2
0
        public virtual void OnDropOutsidePort(Edge edge, Vector2 position)
        {
            this.graphView.RegisterCompleteObjectUndo("Disconnect edge");

            //If the edge was already existing, remove it
            if (!edge.isGhostEdge)
            {
                graphView.Disconnect(edge as EdgeView);
            }

            // when on of the port is null, then the edge was created and dropped outside of a port
            if (edge.input == null || edge.output == null)
            {
                Vector2 mousePos = graphView.ChangeCoordinatesTo(graphView.contentViewContainer, position);

                // Empirical offset:
                mousePos += new Vector2(-10f, -18);

                // TODO: function
                this.graphView.RegisterCompleteObjectUndo("Added relay node ");
                var relayNode = BaseNode.CreateFromType <RelayNode>(mousePos);
                var relayView = graphView.AddNode(relayNode);

                // Connect to the new relay node:
                var  port    = edge.output ?? edge.input;
                var  pv      = port as PortView;
                bool isInput = edge.input == null;

                var p = pv.owner.nodeTarget.GetPort(pv.fieldName, pv.portData.identifier);

                // Wait for node to be created ...
                graphView.schedule.Execute(() => {
                    // We can't use edge here because it have been destroyed
                    if (isInput)
                    {
                        var newEdge = graphView.graph.Connect(relayNode.inputPorts[0], p);
                        graphView.ConnectView(new EdgeView()
                        {
                            userData = newEdge,
                            input    = relayView.GetPortViewFromFieldName(newEdge.inputFieldName, newEdge.inputPortIdentifier),
                            output   = pv.owner.GetPortViewFromFieldName(newEdge.outputFieldName, newEdge.outputPortIdentifier)
                        });
                    }
                    else
                    {
                        var newEdge = graphView.graph.Connect(p, relayNode.outputPorts[0]);
                        graphView.ConnectView(new EdgeView()
                        {
                            userData = newEdge,
                            input    = pv.owner.GetPortViewFromFieldName(newEdge.inputFieldName, newEdge.inputPortIdentifier),
                            output   = relayView.GetPortViewFromFieldName(newEdge.outputFieldName, newEdge.outputPortIdentifier)
                        });
                    }
                }).ExecuteLater(1);
            }

            //TODO: open new nodes selector and connect the created node if there is one
        }
Пример #3
0
        public void OnDropOutsidePort(Edge edge, Vector2 position)
        {
            this.graphView.RegisterCompleteObjectUndo("Disconnect edge");

            //If the edge was already existing, remove it
            if (!edge.isGhostEdge)
            {
                graphView.Disconnect(edge as EdgeView);
            }

            //TODO: open new nodes selector and connect the created node if there is one
        }
        public virtual void OnDropOutsidePort(Edge edge, Vector2 position)
        {
            this.graphView.RegisterCompleteObjectUndo("Disconnect edge");

            //If the edge was already existing, remove it
            if (!edge.isGhostEdge)
            {
                graphView.Disconnect(edge as EdgeView);
            }

            // when on of the port is null, then the edge was created and dropped outside of a port
            if (edge.input == null || edge.output == null)
            {
                ShowNodeCreationMenuFromEdge(edge as EdgeView, position);
            }
        }