void AddBehaviour(CompBehaviour2 cb) { int oldCount = (cb.behaviours != null) ? cb.behaviours.Length : 0; FlockBehaviour2[] newBehaviours = new FlockBehaviour2[oldCount + 1]; float[] newWeights = new float[oldCount + 1]; for (int i = 0; i < oldCount; i++) { newBehaviours[i] = cb.behaviours[i]; newWeights[i] = cb.weights[i]; } newWeights[oldCount] = 1f; cb.behaviours = newBehaviours; cb.weights = newWeights; }
void RemoveBehaviour(CompBehaviour2 cb) { int oldCount = cb.behaviours.Length; if (oldCount == 1) { cb.behaviours = null; cb.weights = null; return; } FlockBehaviour2[] newBehaviours = new FlockBehaviour2[oldCount - 1]; float[] newWeights = new float[oldCount - 1]; for (int i = 0; i < oldCount - 1; i++) { newBehaviours[i] = cb.behaviours[i]; newWeights[i] = cb.weights[i]; } cb.behaviours = newBehaviours; cb.weights = newWeights; }