public bool OnSelectEntry(SearchTreeEntry entry, SearchWindowContext context) { var nodeEntry = (NodeTemplate)entry.userData; var nodeEditor = CreateNode((NodeTemplate)entry.userData); var windowMousePosition = m_editorWindow.rootVisualElement.ChangeCoordinatesTo(m_editorWindow.rootVisualElement.parent, context.screenMousePosition - m_editorWindow.position.position); var graphMousePosition = m_graphView.contentViewContainer.WorldToLocal(windowMousePosition); nodeEditor.Position = new Vector3(graphMousePosition.x, graphMousePosition.y, 0); m_editorView.AddNode(nodeEditor, nodeEntry.Title.Last()); if (ConnectedVisualPort != null) { var connectedSlotReference = ConnectedVisualPort.PortDescription.Owner.FindSlot <PortDescription>(ConnectedVisualPort.PortDescription.MemberName); List <PortDescription> slots = new List <PortDescription>(); if (connectedSlotReference.IsInputSlot) { nodeEditor.GetOutputSlots(slots); } else if (connectedSlotReference.IsOutputSlot) { nodeEditor.GetInputSlots(slots); } foreach (var slot in slots) { if (!slot.IsCompatibleWith(connectedSlotReference)) { continue; } if (slot.VisualPort.connected) { continue; } var edge = connectedSlotReference.VisualPort.ConnectTo(slot.VisualPort); m_editorView.AddEdge(edge); connectedSlotReference = null; NodeNeedsRepositioning = true; TargetPosition = graphMousePosition; break; } } return(true); }
public void OnDrop(GraphView graphView, Edge edge) { m_editorView.AddEdge(edge); }