From 5615a28ece0bf70e8258e586ef1217f415f2f10b Mon Sep 17 00:00:00 2001 From: Nolan Darilek Date: Mon, 13 Jun 2022 09:24:30 -0500 Subject: [PATCH] Reset source when panner strategy changes or is removed. --- src/lib.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index edb8ef6..8b81259 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -199,6 +199,27 @@ fn swap_buffers( } } +fn change_panner_strategy( + changed: Query>, + removed: RemovedComponents, + mut sounds: Query<&mut Sound>, +) { + let mut check = vec![]; + for entity in changed.iter() { + check.push(entity); + } + for entity in removed.iter() { + check.push(entity); + } + for entity in check.iter() { + if let Ok(mut sound) = sounds.get_mut(*entity) { + if sound.source.is_some() { + sound.source = None; + } + } + } +} + pub fn update_sound_properties( context: Res, buffers: Res>, @@ -571,6 +592,10 @@ impl Plugin for SynthizerPlugin { CoreStage::PostUpdate, swap_buffers.before(update_sound_properties), ) + .add_system_to_stage( + CoreStage::PostUpdate, + change_panner_strategy.before(update_sound_properties), + ) .add_system_to_stage( CoreStage::PostUpdate, update_listener