public bool OnSelectEntry(SearchTreeEntry entry, SearchWindowContext context) { var rootElement = graphView.editorWindow.rootVisualElement; var worldPosition = rootElement.ChangeCoordinatesTo(rootElement.parent, context.screenMousePosition - graphView.editorWindow.position.position); var node = graphView.CreateNewNode((NodeEntry)entry.userData, graphView.contentViewContainer.WorldToLocal(worldPosition)); if (ConnectedPort != null) { Port other = ConnectedPort.direction == Direction.Input ? node.ChildrenPort : node.ParentPort; if (other != null) { //Disconnect old ports if necessary if (other.capacity == Port.Capacity.Single && other.connected) { graphView.DeleteElements(other.connections); } if (ConnectedPort.capacity == Port.Capacity.Single && ConnectedPort.connected) { graphView.DeleteElements(ConnectedPort.connections); } graphView.AddElement(ConnectedPort.ConnectTo(other)); //Connect ((TreeGraphNode)(ConnectedPort.direction == Direction.Input ? ConnectedPort : other).node).RecalculateOrder(); } ConnectedPort = null; } return(true); }
TreeGraphNode DeserializeNode(TreeNodeData data) { NodeInfo info = serializedNameToInfo.TryGetValue(data.nodeTypeSerializableName) ?? throw new Exception($"Unexpected serialized name {data.nodeTypeSerializableName}"); TreeGraphNode node = graphView.CreateNewNode(info, data.position, data.parameters); node.GUID = data.GUID; //Children TreeGraphNode child = null; for (int i = 0; i < data.children.Length; i++) { child = DeserializeNode(allData[data.children[i]]); graphView.AddElement(child.ParentPort.ConnectTo(node.ChildrenPort)); } child?.RecalculateOrder(); //This will calculate the order of its siblings too return(node); }