Skip to content

Commit af0d896

Browse files
committed
Fix connecting and disconnecting nodes when no nodes left in the sequence
1 parent b452eb4 commit af0d896

File tree

1 file changed

+14
-18
lines changed

1 file changed

+14
-18
lines changed

Assets/RGLUnityPlugin/Scripts/LowLevelWrappers/RGLNodeSequence.cs

+14-18
Original file line numberDiff line numberDiff line change
@@ -612,12 +612,13 @@ private void ConnectNode(RGLNodeHandle nodeToConnect)
612612
throw new RGLException($"Attempted to connect node '{nodeToConnect.Identifier}' twice!");
613613
}
614614

615-
// Collect previous and next nodes that are connected
615+
// Collect previous and next nodes to the nodeToConnect that are connected
616616
RGLNodeHandle[] prevNodes = GetPreviousNodes(nodeToConnect, true);
617617
RGLNodeHandle[] nextNodes = GetNextNodes(nodeToConnect, true);
618618

619-
// Nodes are connected with each other. Need to disconnect them.
620-
if (prevNodes.Length != 0 && nextNodes.Length != 0)
619+
// If there are any other connected (active) nodes in this sequence, prevNodes and nextNodes are connected
620+
// Before connecting a new node between them, we have to disconnect them first
621+
if (GetConnectedNodesCount() > 0)
621622
{
622623
foreach (RGLNodeHandle prevNode in prevNodes)
623624
{
@@ -648,7 +649,7 @@ private void DisconnectNode(RGLNodeHandle nodeToDisconnect)
648649
throw new RGLException($"Attempted to disconnect node '{nodeToDisconnect.Identifier}' that is not connected!");
649650
}
650651

651-
// Collect previous and next nodes that are connected
652+
// Collect previous and next nodes to the nodeToDisconnect that are connected
652653
RGLNodeHandle[] prevNodes = GetPreviousNodes(nodeToDisconnect, true);
653654
RGLNodeHandle[] nextNodes = GetNextNodes(nodeToDisconnect, true);
654655

@@ -662,19 +663,11 @@ private void DisconnectNode(RGLNodeHandle nodeToDisconnect)
662663
RGLNativeAPI.GraphNodeRemoveChild(nodeToDisconnect.Node, nextNode.Node);
663664
}
664665

665-
bool anyNodeRemained = false;
666-
foreach (RGLNodeHandle node in prevNodes.ToList().Concat(nextNodes.ToList()))
667-
{
668-
if (nodes.Contains(node))
669-
{
670-
anyNodeRemained = true;
671-
break;
672-
}
673-
}
666+
nodeToDisconnect.Connected = false;
674667

675-
// Connect nodes that have become adjacent
676-
// If there is no remaining nodes in this sequence - skip connecting
677-
if (prevNodes.Length != 0 && nextNodes.Length != 0 && anyNodeRemained)
668+
// If there are any other connected (active) nodes in this sequence, connect nodes that have become adjacent to each other
669+
// Otherwise, we don't want to connect parent and child NodeSequences by omitting the current NodeSequence
670+
if (GetConnectedNodesCount() > 0)
678671
{
679672
foreach (RGLNodeHandle prevNode in prevNodes)
680673
{
@@ -684,8 +677,6 @@ private void DisconnectNode(RGLNodeHandle nodeToDisconnect)
684677
}
685678
}
686679
}
687-
688-
nodeToDisconnect.Connected = false;
689680
}
690681

691682
//// NODE GETTERS ////
@@ -755,6 +746,11 @@ private RGLNodeHandle[] GetNextNodes(RGLNodeHandle referenceNode, bool mustBeCon
755746
return outNodes.ToArray();
756747
}
757748

749+
private int GetConnectedNodesCount()
750+
{
751+
return nodes.Count(n => n.Connected);
752+
}
753+
758754
private void DisconnectAllChilds()
759755
{
760756
foreach (RGLNodeSequence nodeSequence in childs.ToList())

0 commit comments

Comments
 (0)