private void UpdateChildren([NotNull] SerializedProperty serializedBehaviorDataArray) { var removedEdges = new List <Edge>(); for (int i = 0, count = serializedBehaviorDataArray.arraySize; i < count; ++i) { SerializedProperty serializedBehaviorData = serializedBehaviorDataArray.GetArrayElementAtIndex(i); var serializedBehavior = (SerializedBehavior_Base)serializedBehaviorData .FindPropertyRelative(SerializedBehaviorPropertyName).objectReferenceValue; SerializedBehaviorTreeNode node = FindNode(serializedBehavior); SerializedProperty children = serializedBehaviorData.FindPropertyRelative(ChildrenIndicesPropertyName); node.SetOutputCapacity(removedEdges, children.arraySize); for (int edgeIndex = 0, edgeCount = removedEdges.Count; edgeIndex < edgeCount; ++edgeIndex) { Edge removedEdge = removedEdges[edgeIndex]; ((SerializedBehaviorTreeNode)removedEdge.input.node).DisconnectParent(); RemoveElement(removedEdge); } removedEdges.Clear(); for (int childIndex = 0, childrenCount = children.arraySize; childIndex < childrenCount; ++childIndex) { int childBehaviorIndex = children.GetArrayElementAtIndex(childIndex).intValue; if (childBehaviorIndex < 0) { if (node.GetChild(childIndex) != null) { Edge edge = node.RemoveChild(childIndex); ((SerializedBehaviorTreeNode)edge.input.node).DisconnectParent(); RemoveElement(edge); } continue; } var child = (SerializedBehavior_Base)serializedBehaviorDataArray .GetArrayElementAtIndex(childBehaviorIndex) .FindPropertyRelative(SerializedBehaviorPropertyName).objectReferenceValue; if (node.GetChild(childIndex)?.dependedSerializedBehavior == child) { continue; } Edge previousEdge = node.RemoveChild(childIndex); if (previousEdge != null) { ((SerializedBehaviorTreeNode)previousEdge.input.node).DisconnectParent(); RemoveElement(previousEdge); } AddElement(node.SetChild(FindNode(child), childIndex)); } } }
private void RemoveConnections([NotNull] SerializedBehaviorTreeNode node) { for (int edgeIndex = 0, edgeCount = node.outputEdgeCount; edgeIndex < edgeCount; ++edgeIndex) { Edge edge = node.RemoveChild(edgeIndex); if (edge != null) { ((SerializedBehaviorTreeNode)edge.input.node).DisconnectParent(); RemoveElement(edge); } } for (int nodeIndex = 0, nodeCount = m_nodes.Count; nodeIndex < nodeCount; ++nodeIndex) { SerializedBehaviorTreeNode otherNode = m_nodes[nodeIndex]; for (int childIndex = 0, childrenCount = otherNode.outputEdgeCount; childIndex < childrenCount; ++childIndex) { if (otherNode.GetChild(childIndex) == node) { Edge edge = otherNode.RemoveChild(childIndex); if (edge != null) { RemoveElement(edge); } } } } }