static void CreateLink(BaseGraph graph, BaseGraphCommand command, string inputCommand) { //get nodes from the graph: BaseNode fromNode, toNode; GetNodes(graph, command, out fromNode, out toNode, inputCommand); //Create the first linkable anchors we found: foreach (var outAnchor in fromNode.outputAnchors) { foreach (var inAnchor in toNode.inputAnchors) { if (AnchorUtils.AnchorAreAssignable(outAnchor, inAnchor)) { //if the input anchor is already linked, find another if (inAnchor.linkCount == 1) { continue; } graph.CreateLink(outAnchor, inAnchor, false); return; } } } Debug.LogError("Can't link " + fromNode + " with " + toNode); }
//disable anchors which are unlinkable with the anchor in parameter public void DisableIfUnlinkable(Anchor anchorToLink) { foreach (var anchor in anchors) { if (!AnchorUtils.AnchorAreAssignable(anchorToLink, anchor)) { anchor.isLinkable = false; } } }
//create a link without checking for duplication public NodeLink CreateLink(Anchor fromAnchor, Anchor toAnchor, bool raiseEvents = true) { NodeLink link = new NodeLink(); Anchor fAnchor = fromAnchor; Anchor tAnchor = toAnchor; if (OnPreLinkCreated != null && raiseEvents) { OnPreLinkCreated(); } //swap anchors if input/output are reversed if (fromAnchor.anchorType != AnchorType.Output) { tAnchor = fromAnchor; fAnchor = toAnchor; } if (!AnchorUtils.AnchorAreAssignable(fAnchor, tAnchor)) { Debug.LogWarning("[BaseGraph] attempted to create a link between unlinkable anchors: " + fAnchor.fieldType + " into " + tAnchor.fieldType); return(null); } link.Initialize(fAnchor, tAnchor); nodeLinkTable.AddLink(link); //raise link creation event if (OnLinkCreated != null && raiseEvents) { OnLinkCreated(link); } link.fromNode.AddLink(link); link.toNode.AddLink(link); if (OnPostLinkCreated != null && raiseEvents) { OnPostLinkCreated(link); } return(link); }
public NodeLink SafeCreateLink(Anchor fromAnchor, Anchor toAnchor, bool raiseEvents = true) { Anchor fAnchor = fromAnchor; Anchor tAnchor = toAnchor; //swap anchors if input/output are reversed if (fromAnchor.anchorType != AnchorType.Output) { tAnchor = fromAnchor; fAnchor = toAnchor; } if (!AnchorUtils.AnchorAreAssignable(fAnchor, tAnchor)) { return(null); } if (tAnchor.linkCount > 0) { tAnchor.RemoveAllLinks(); } return(CreateLink(fAnchor, tAnchor, raiseEvents)); }