Пример #1
0
    private void LinkNodes(Port output, Port input)
    {
        var tempEdge = new Edge
        {
            input  = input,
            output = output
        };

        tempEdge?.input?.Connect(tempEdge);
        tempEdge?.output?.Connect(tempEdge);
        targetGraphView.Add(tempEdge);
    }
Пример #2
0
    public bool OnSelectEntry(SearchTreeEntry SearchTreeEntry, SearchWindowContext context)
    {
        var worldMousePosition = window.rootVisualElement.ChangeCoordinatesTo(window.rootVisualElement.parent,
                                                                              context.screenMousePosition - window.position.position);
        var localMousePosition = graphView.contentViewContainer.WorldToLocal(worldMousePosition);

        BaseNode       node = (BaseNode)SearchTreeEntry.userData;
        ActionNodeData and  = new ActionNodeData
        {
            Position      = new Rect(localMousePosition, graphView.DefaultNodeSize),
            GUID          = Guid.NewGuid().ToString(),
            OutputPortIDs = new List <string>(),
            NodeType      = node.NodeType.AssemblyQualifiedName
        };
        BaseNode temp = NodeFactory.CreateNode(and);

        temp?.Draw(graphView);

        //if tempEdge is not null, this means that the search window
        if (graphView.TempEdge != null && temp != null)
        {
            //get the inpût port of the new node
            var tempInput = graphView.GetInputPorts(temp).ToList();

            if (tempInput.Count == 0)
            {
                graphView.TempPort = null;
                graphView.TempEdge = null;

                return(true);
            }
            var inputPort = tempInput.First();

            //if the output port is single and already connected. Must disconnect it.
            if (graphView.TempPort.capacity == Port.Capacity.Single && graphView.TempPort.connected)
            {
                var edge = graphView.edges.ToList().Where(x => x.output == graphView.TempPort);
                if (edge.Any())
                {
                    var e = edge.First();
                    e.input.Disconnect(e);
                    e.output.Disconnect(e);
                    graphView.RemoveElement(e);
                }
            }
            var tempEdge = new Edge
            {
                input  = inputPort,
                output = graphView.TempPort
            };
            inputPort.Connect(tempEdge);
            graphView.TempPort.Connect(tempEdge);
            graphView.Add(tempEdge);

            graphView.TempPort = null;
            graphView.TempEdge = null;

            return(true);
        }

        //Return false doesn't close window
        return(true);
    }