Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 30 additions & 4 deletions Scripts/NodePort.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Reflection;
using UnityEngine;
Expand All @@ -19,7 +19,7 @@ public NodePort Connection {
}
}

public IO direction {
public IO direction {
get { return _direction; }
internal set { _direction = value; }
}
Expand Down Expand Up @@ -337,16 +337,33 @@ public void SwapConnections(NodePort targetPort) {
int aConnectionCount = connections.Count;
int bConnectionCount = targetPort.connections.Count;

List<List<Vector2>> aReroutePoints = new List<List<Vector2>>();
List<List<Vector2>> bReroutePoints = new List<List<Vector2>>();

List<NodePort> portConnections = new List<NodePort>();
List<NodePort> targetPortConnections = new List<NodePort>();

// Cache port connections
for (int i = 0; i < aConnectionCount; i++)
{
portConnections.Add(connections[i].Port);
aReroutePoints.Add(new List<Vector2>());
for (int e = 0; e < connections[i].reroutePoints.Count; e++)
{
aReroutePoints[i].Add(connections[i].reroutePoints[e]);
}
}

// Cache target port connections
// Cache target port connections and reroute points
for (int i = 0; i < bConnectionCount; i++)
{
targetPortConnections.Add(targetPort.connections[i].Port);
bReroutePoints.Add(new List<Vector2>());
for (int e = 0; e < targetPort.connections[i].reroutePoints.Count; e++)
{
bReroutePoints[i].Add(targetPort.connections[i].reroutePoints[e]);
}
}

ClearConnections();
targetPort.ClearConnections();
Expand All @@ -359,6 +376,15 @@ public void SwapConnections(NodePort targetPort) {
for (int i = 0; i < targetPortConnections.Count; i++)
Connect(targetPortConnections[i]);

// Add the reroute poins
for (int i = 0; i < aConnectionCount; i++)
{
targetPort.connections[i].reroutePoints = aReroutePoints[i];
}
for (int i = 0; i < bConnectionCount; i++)
{
connections[i].reroutePoints = bReroutePoints[i];
}
}

/// <summary> Copy all connections pointing to a node and add them to this one </summary>
Expand Down Expand Up @@ -415,4 +441,4 @@ private NodePort GetPort() {
}
}
}
}
}