1
0
mirror of https://github.com/Siccity/xNode.git synced 2026-02-17 20:41:40 +08:00

Added Node.OnRemoveConnection

This commit is contained in:
Thor Brigsted 2017-12-03 23:20:33 +01:00
parent 29dd6e0c62
commit 2291531ceb
2 changed files with 12 additions and 2 deletions

View File

@ -134,10 +134,14 @@ namespace XNode {
} }
#endregion #endregion
/// <summary> Called whenever a connection is being made between two <see cref="NodePort"/>s</summary> /// <summary> Called after a connection between two <see cref="NodePort"/>s is created </summary>
/// <param name="from">Output</param> <param name="to">Input</param> /// <param name="from">Output</param> <param name="to">Input</param>
public virtual void OnCreateConnection(NodePort from, NodePort to) { } public virtual void OnCreateConnection(NodePort from, NodePort to) { }
/// <summary> Called after a connection is removed from this port </summary>
/// <param name="from">Output</param> <param name="to">Input</param>
public virtual void OnRemoveConnection(NodePort port) { }
/// <summary> Disconnect everything from this node </summary> /// <summary> Disconnect everything from this node </summary>
public void ClearConnections() { public void ClearConnections() {
foreach (NodePort port in Ports) port.ClearConnections(); foreach (NodePort port in Ports) port.ClearConnections();

View File

@ -204,16 +204,22 @@ namespace XNode {
return false; return false;
} }
/// <summary> Disconnect this port from another port </summary>
public void Disconnect(NodePort port) { public void Disconnect(NodePort port) {
NodePort from = direction == IO.Input ? port : this;
NodePort to = direction == IO.Input ? this : port;
// Remove this ports connection to the other
for (int i = connections.Count - 1; i >= 0; i--) { for (int i = connections.Count - 1; i >= 0; i--) {
//Remove matching ports.
if (connections[i].Port == port) { if (connections[i].Port == port) {
connections.RemoveAt(i); connections.RemoveAt(i);
node.OnRemoveConnection(this);
} }
} }
// Remove the other ports connection to this port
for (int i = 0; i < port.connections.Count; i++) { for (int i = 0; i < port.connections.Count; i++) {
if (port.connections[i].Port == this) { if (port.connections[i].Port == this) {
port.connections.RemoveAt(i); port.connections.RemoveAt(i);
port.node.OnRemoveConnection(port);
} }
} }
} }