///---------------------------------------------------------------------------------------------- ///Returns whether source and target nodes can generaly be connected together. ///This only validates max in/out connections that source and target nodes has. ///Providing an existing ref connection, will bypass source/target validation respectively if that connection is already connected to that source/target node. public static bool IsNewConnectionAllowed(Node sourceNode, Node targetNode, Connection refConnection = null) { if (sourceNode == null || targetNode == null) { ParadoxNotion.Services.Logger.LogWarning("A Node Provided is null.", "Editor", targetNode); return(false); } if (sourceNode == targetNode) { ParadoxNotion.Services.Logger.LogWarning("Node can't connect to itself.", "Editor", targetNode); return(false); } if (refConnection == null || refConnection.sourceNode != sourceNode) { if (sourceNode.outConnections.Count >= sourceNode.maxOutConnections && sourceNode.maxOutConnections != -1) { ParadoxNotion.Services.Logger.LogWarning("Source node can have no more out connections.", "Editor", sourceNode); return(false); } } if (refConnection == null || refConnection.targetNode != targetNode) { if (targetNode.maxInConnections <= targetNode.inConnections.Count && targetNode.maxInConnections != -1) { ParadoxNotion.Services.Logger.LogWarning("Target node can have no more in connections.", "Editor", targetNode); return(false); } if (targetNode == targetNode.graph.primeNode && targetNode.maxInConnections == 1) { ParadoxNotion.Services.Logger.LogWarning("Target node can have no more in connections.", "Editor", targetNode); return(false); } } var final = true; final &= sourceNode.CanConnectToTarget(targetNode); final &= targetNode.CanConnectFromSource(sourceNode); return(final); }
///---------------------------------------------------------------------------------------------- ///Returns whether source and target nodes can generaly be connected together. ///This only validates max in/out connections that source and target nodes has, along with other validations. ///Providing an existing refConnection, will bypass source/target validation respectively if that connection is already connected to that source/target node. public static bool IsNewConnectionAllowed(Node sourceNode, Node targetNode, Connection refConnection = null) { if (sourceNode == null || targetNode == null) { Logger.LogWarning("A Node Provided is null.", LogTag.EDITOR, targetNode); return(false); } if (sourceNode == targetNode && !sourceNode.canSelfConnect) { Logger.LogWarning("Node can't connect to itself.", LogTag.EDITOR, targetNode); return(false); } if (refConnection == null || refConnection.sourceNode != sourceNode) { if (sourceNode.outConnections.Count >= sourceNode.maxOutConnections && sourceNode.maxOutConnections != -1) { Logger.LogWarning("Source node can have no more out connections.", LogTag.EDITOR, sourceNode); return(false); } } if (refConnection == null || refConnection.targetNode != targetNode) { if (targetNode.maxInConnections <= targetNode.inConnections.Count && targetNode.maxInConnections != -1) { Logger.LogWarning("Target node can have no more in connections.", LogTag.EDITOR, targetNode); return(false); } } var final = true; final &= sourceNode.CanConnectToTarget(targetNode); final &= targetNode.CanConnectFromSource(sourceNode); return(final); }