protected override void RemoveAt(TList collection, int index) { NodePort indexPort = GetNodePort(index); if (indexPort == null) { Debug.LogWarning($"No port found at index {index}"); } lastRemovedConnections.Clear(); if (indexPort != null) { lastRemovedConnections.AddRange(indexPort.GetConnections()); // Clear the removed ports connections indexPort.ClearConnections(); } // Cache the last port because I'm about to remove it NodePort lastPort = GetNodePort(ChildCount - 1); // Move following connections one step up to replace the missing connection for (int k = index + 1; k < ChildCount; k++) { NodePort kPort = GetNodePort(k); if (kPort == null) { continue; } NodePort k1Port = GetNodePort(k - 1); // Port k - 1 missing means I need to actually rename a port instead // Create k -1, add all the correct connections ... leave K alone because he existed if (k1Port == null) { k1Port = ReplaceNodeForRemove(k - 1); } for (int j = 0; j < kPort.ConnectionCount; j++) { NodePort other = kPort.GetConnection(j); kPort.Disconnect(other); k1Port.Connect(other); } } // Remove the last dynamic port, to avoid messing up the indexing if (lastPort != null) { lastPort.node.RemoveDynamicPort(lastPort); } base.RemoveAt(collection, index); this.ForceUpdateChildCount(); }
/// <summary> /// Handles the internal behavior for when a node is connected to another node. /// </summary> /// <param name="from">Start of connection</param> /// <param name="to">End of connection</param> public override void OnCreateConnection(NodePort from, NodePort to) { if (from.ConnectionCount > 1) { from.ClearConnections(); from.Connect(to); } // This gets the port index string indexName = from.fieldName.Replace("childNodes ", ""); int index = int.Parse(indexName); // Sets the target ID in the child node ((DialogueNode)from.node).childNodes[index].targetID = ((DialogueNode)to.node).GetID(); base.OnCreateConnection(from, to); }