// Add and remove behavior methods void AddBehavior(CompositeBehaviorWithLeader cb) { // get the original size of the array int oldCount = (cb.behaviors != null ? cb.behaviors.Length : 0); FlockBehaviorWithLeader[] newBehaviors = new FlockBehaviorWithLeader[oldCount + 1]; float[] newWeights = new float[oldCount + 1]; for (int i = 0; i < oldCount; i++) { newBehaviors[i] = cb.behaviors[i]; newWeights[i] = cb.weights[i]; } newWeights[oldCount] = 1f; cb.behaviors = newBehaviors; cb.weights = newWeights; }
void RemoveBehavior(CompositeBehaviorWithLeader cb) { // get the original size of the array int oldCount = cb.behaviors.Length; if (oldCount == 1) { cb.behaviors = null; cb.weights = null; return; } FlockBehaviorWithLeader[] newBehaviors = new FlockBehaviorWithLeader[oldCount - 1]; float[] newWeights = new float[oldCount - 1]; for (int i = 0; i < oldCount - 1; i++) { newBehaviors[i] = cb.behaviors[i]; newWeights[i] = cb.weights[i]; } cb.behaviors = newBehaviors; cb.weights = newWeights; }