void AddBehavior(CompositeBehaviorV2 cb) { int oldCount = (cb.behaviors != null) ? cb.behaviors.Length : 0; HerdBehavior[] newBehaviors = new HerdBehavior[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(CompositeBehaviorV2 cb) { int oldCount = cb.behaviors.Length; if (oldCount == 1) { cb.behaviors = null; cb.weights = null; return; } HerdBehavior[] newBehaviors = new HerdBehavior[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; }