mirror of
https://github.com/Siccity/xNode.git
synced 2026-02-09 16:48:43 +08:00
Improved handling of invalid connections
This commit is contained in:
parent
d498484802
commit
bb15a8fdd3
@ -69,6 +69,7 @@ public partial class NodeEditorWindow {
|
|||||||
if (hoveredPort.IsOutput) {
|
if (hoveredPort.IsOutput) {
|
||||||
draggedOutput = hoveredPort;
|
draggedOutput = hoveredPort;
|
||||||
} else {
|
} else {
|
||||||
|
hoveredPort.VerifyConnections();
|
||||||
if (hoveredPort.IsConnected) {
|
if (hoveredPort.IsConnected) {
|
||||||
NodePort output = hoveredPort.Connection;
|
NodePort output = hoveredPort.Connection;
|
||||||
hoveredPort.Disconnect(output);
|
hoveredPort.Disconnect(output);
|
||||||
|
|||||||
@ -46,12 +46,11 @@ public class NodePort {
|
|||||||
|
|
||||||
/// <summary> Checks all connections for invalid references, and removes them. </summary>
|
/// <summary> Checks all connections for invalid references, and removes them. </summary>
|
||||||
public void VerifyConnections() {
|
public void VerifyConnections() {
|
||||||
for (int i = 0; i < connections.Count; i++) {
|
for (int i = connections.Count-1; i >= 0; i--) {
|
||||||
if (connections[i].node != null &&
|
if (connections[i].node != null &&
|
||||||
!string.IsNullOrEmpty(connections[i].fieldName) &&
|
!string.IsNullOrEmpty(connections[i].fieldName) &&
|
||||||
connections[i].node.GetPortByFieldName(connections[i].fieldName) != null)
|
connections[i].node.GetPortByFieldName(connections[i].fieldName) != null)
|
||||||
continue;
|
continue;
|
||||||
Debug.LogWarning("Removed invalid connection");
|
|
||||||
connections.RemoveAt(i);
|
connections.RemoveAt(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -97,7 +96,8 @@ public class NodePort {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void Disconnect(NodePort port) {
|
public void Disconnect(NodePort port) {
|
||||||
for (int i = 0; i < connections.Count; 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);
|
||||||
}
|
}
|
||||||
@ -128,7 +128,9 @@ public class NodePort {
|
|||||||
fieldName = port.fieldName;
|
fieldName = port.fieldName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary> Returns the port that this <see cref="PortConnection"/> points to </summary>
|
||||||
private NodePort GetPort() {
|
private NodePort GetPort() {
|
||||||
|
if (node == null || string.IsNullOrEmpty(fieldName)) return null;
|
||||||
|
|
||||||
for (int i = 0; i < node.OutputCount; i++) {
|
for (int i = 0; i < node.OutputCount; i++) {
|
||||||
if (node.outputs[i].fieldName == fieldName) return node.outputs[i];
|
if (node.outputs[i].fieldName == fieldName) return node.outputs[i];
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user