internal void DestroySoundInstances(AudioListenerComponent listener) { var deferRemoval = new List <SoundInstance>(); foreach (var instance in InstanceToListener.Keys) { deferRemoval.Add(instance); } foreach (var soundInstance in deferRemoval) { DestroySoundInstance(soundInstance); } for (var i = 0; i < FastInstances.Count; i++) { var instance = FastInstances[i]; if (instance.Listener == listener.Listener) { //Decrement the loop counter to iterate this index again, since later elements will get moved down during the remove operation. FastInstances.RemoveAt(i--); instance.Dispose(); } } }
internal void DestroySoundInstances(AudioListenerComponent listener) { foreach (var instance in InstanceToListener.Keys) { instance.Dispose(); listener.AttachedInstances.Remove(instance); } InstanceToListener.Clear(); for (var i = 0; i < FastInstances.Count; i++) { var instance = FastInstances[i]; if (instance.Listener == listener.Listener) { //Decrement the loop counter to iterate this index again, since later elements will get moved down during the remove operation. FastInstances.RemoveAt(i--); DestroySoundInstance(instance); } } }