diff --git a/src/sound/icon.rs b/src/sound/icon.rs index b042c16..095d9bc 100644 --- a/src/sound/icon.rs +++ b/src/sound/icon.rs @@ -121,76 +121,79 @@ fn update( ) in icons.iter_mut() { let entity = if visibility.is_some() { - icon_entity + Some(icon_entity) + } else if parent.is_some() { + Some(**parent.unwrap()) } else { - **parent.unwrap() + None }; - if visible.contains(&entity) { - let looping = sound.looping; - if looping { - sound.paused = false; - } else if let Some(interval) = icon.interval.as_mut() { - interval.tick(time.delta()); - if interval.finished() { + if let Some(entity) = entity { + if visible.contains(&entity) { + if sound.looping { sound.paused = false; - sound.restart = true; - interval.reset(); + } else if let Some(interval) = icon.interval.as_mut() { + interval.tick(time.delta()); + if interval.finished() { + sound.paused = false; + sound.restart = true; + interval.reset(); + } } - } - let buffer = asset_server.get_handle(icon.sound); - sound.looping = icon.interval.is_none(); - if sound.buffer != buffer { - sound.buffer = buffer; - } - sound.gain = icon.gain; - sound.pitch = icon.pitch; - if let Some(v) = icon.reference_distance { - let insert = if let Some(v2) = distance_ref { - v != **v2 - } else { - true - }; - if insert { - commands.run_if_exists(icon_entity, move |mut entity| { - entity.insert(DistanceRef(v)); - }) + let buffer = asset_server.get_handle(icon.sound); + if sound.buffer != buffer { + sound.buffer = buffer; } - } else if distance_ref.is_some() { - commands.run_if_exists(icon_entity, |mut entity| { - entity.remove::(); - }); - } - if let Some(v) = icon.max_distance { - let insert = if let Some(v2) = distance_max { - v != **v2 - } else { - true - }; - if insert { - commands.run_if_exists(icon_entity, move |mut entity| { - entity.insert(DistanceMax(v)); - }) + sound.gain = icon.gain; + sound.pitch = icon.pitch; + sound.looping = icon.interval.is_none(); + if let Some(v) = icon.reference_distance { + let insert = if let Some(v2) = distance_ref { + v != **v2 + } else { + true + }; + if insert { + commands.run_if_exists(icon_entity, move |mut entity| { + entity.insert(DistanceRef(v)); + }) + } + } else if distance_ref.is_some() { + commands.run_if_exists(icon_entity, |mut entity| { + entity.remove::(); + }); } - } else if distance_max.is_some() { - commands.run_if_exists(icon_entity, |mut entity| { - entity.remove::(); - }); - } - if let Some(v) = icon.rolloff { - let insert = if let Some(v2) = rolloff { - v != **v2 - } else { - true - }; - if insert { - commands.run_if_exists(icon_entity, move |mut entity| { - entity.insert(Rolloff(v)); - }) + if let Some(v) = icon.max_distance { + let insert = if let Some(v2) = distance_max { + v != **v2 + } else { + true + }; + if insert { + commands.run_if_exists(icon_entity, move |mut entity| { + entity.insert(DistanceMax(v)); + }) + } + } else if distance_max.is_some() { + commands.run_if_exists(icon_entity, |mut entity| { + entity.remove::(); + }); + } + if let Some(v) = icon.rolloff { + let insert = if let Some(v2) = rolloff { + v != **v2 + } else { + true + }; + if insert { + commands.run_if_exists(icon_entity, move |mut entity| { + entity.insert(Rolloff(v)); + }) + } + } else if rolloff.is_some() { + commands.run_if_exists(icon_entity, |mut entity| { + entity.remove::(); + }); } - } else if rolloff.is_some() { - commands.run_if_exists(icon_entity, |mut entity| { - entity.remove::(); - }); } } else { sound.paused = true;