public void RemoveSound(SoundObject2D soundToRemove) { if (this.object2DToSounds.TryGetValue(soundToRemove.Owner, out List <SoundObject2D> sounds)) { sounds.Remove(soundToRemove); if (sounds.Count == 0) { this.object2DToSounds.Remove(soundToRemove.Owner); } } soundToRemove.Stop(); soundToRemove.Dispose(); }
public void PlaySound(SoundObject2D soundToPlay, bool isLooping = false) { List <SoundObject2D> sounds = null; if (this.object2DToSounds.TryGetValue(soundToPlay.Owner, out sounds) == false) { sounds = new List <SoundObject2D>(); this.object2DToSounds[soundToPlay.Owner] = sounds; } sounds.Add(soundToPlay); soundToPlay.Loop = isLooping; soundToPlay.Play(); }