mirror of
https://github.com/Siccity/xNode.git
synced 2026-02-06 15:24:55 +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) {
|
||||
draggedOutput = hoveredPort;
|
||||
} else {
|
||||
hoveredPort.VerifyConnections();
|
||||
if (hoveredPort.IsConnected) {
|
||||
NodePort output = hoveredPort.Connection;
|
||||
hoveredPort.Disconnect(output);
|
||||
|
||||
@ -46,12 +46,11 @@ public class NodePort {
|
||||
|
||||
/// <summary> Checks all connections for invalid references, and removes them. </summary>
|
||||
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 &&
|
||||
!string.IsNullOrEmpty(connections[i].fieldName) &&
|
||||
connections[i].node.GetPortByFieldName(connections[i].fieldName) != null)
|
||||
continue;
|
||||
Debug.LogWarning("Removed invalid connection");
|
||||
connections.RemoveAt(i);
|
||||
}
|
||||
}
|
||||
@ -97,7 +96,8 @@ public class NodePort {
|
||||
}
|
||||
|
||||
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) {
|
||||
connections.RemoveAt(i);
|
||||
}
|
||||
@ -128,7 +128,9 @@ public class NodePort {
|
||||
fieldName = port.fieldName;
|
||||
}
|
||||
|
||||
/// <summary> Returns the port that this <see cref="PortConnection"/> points to </summary>
|
||||
private NodePort GetPort() {
|
||||
if (node == null || string.IsNullOrEmpty(fieldName)) return null;
|
||||
|
||||
for (int i = 0; i < node.OutputCount; i++) {
|
||||
if (node.outputs[i].fieldName == fieldName) return node.outputs[i];
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user