Compare commits
2 Commits
0f4aa54612
...
298012455a
Author | SHA1 | Date | |
---|---|---|---|
298012455a | |||
b60183c448 |
19
src/lib.rs
19
src/lib.rs
|
@ -130,7 +130,7 @@ pub struct Sound {
|
|||
pub paused: bool,
|
||||
pub restart: bool,
|
||||
#[reflect(ignore)]
|
||||
pub generator: Option<syz::BufferGenerator>,
|
||||
pub generator: Option<syz::Generator>,
|
||||
}
|
||||
|
||||
impl Default for Sound {
|
||||
|
@ -194,7 +194,6 @@ fn update_listener(
|
|||
fn add_source_handle(
|
||||
context: Res<syz::Context>,
|
||||
mut query: Query<(
|
||||
Entity,
|
||||
&mut Source,
|
||||
Option<&PannerStrategy>,
|
||||
Option<&GlobalTransform>,
|
||||
|
@ -202,7 +201,7 @@ fn add_source_handle(
|
|||
Option<&ScalarPan>,
|
||||
)>,
|
||||
) {
|
||||
for (entity, mut source, panner_strategy, transform, angular_pan, scalar_pan) in &mut query {
|
||||
for (mut source, panner_strategy, transform, angular_pan, scalar_pan) in &mut query {
|
||||
if source.handle.is_none() {
|
||||
let panner_strategy = panner_strategy.cloned().unwrap_or_default();
|
||||
let handle: syz::Source = if let Some(transform) = transform {
|
||||
|
@ -285,7 +284,7 @@ fn add_generator(
|
|||
handle
|
||||
.add_generator(&generator)
|
||||
.expect("Unable to add generator");
|
||||
sound.generator = Some(generator);
|
||||
sound.generator = Some(generator.into());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -357,7 +356,6 @@ fn change_panner_strategy(
|
|||
fn update_source_properties(
|
||||
context: Res<syz::Context>,
|
||||
mut query: Query<(
|
||||
Entity,
|
||||
&mut Source,
|
||||
Option<&DistanceModel>,
|
||||
Option<&DistanceRef>,
|
||||
|
@ -371,7 +369,6 @@ fn update_source_properties(
|
|||
)>,
|
||||
) {
|
||||
for (
|
||||
entity,
|
||||
mut source,
|
||||
distance_model,
|
||||
distance_ref,
|
||||
|
@ -503,11 +500,16 @@ fn update_sound_properties(mut query: Query<&mut Sound>) {
|
|||
assert!(pitch > 0. && pitch <= 2.);
|
||||
if sound.restart {
|
||||
if let Some(generator) = sound.generator.as_mut() {
|
||||
if let Some(generator) = generator
|
||||
.cast_to::<syz::BufferGenerator>()
|
||||
.expect("Failed to cast")
|
||||
{
|
||||
generator
|
||||
.playback_position()
|
||||
.set(0.)
|
||||
.expect("Failed to restart");
|
||||
}
|
||||
}
|
||||
sound.restart = false;
|
||||
}
|
||||
if let Some(generator) = sound.generator.as_mut() {
|
||||
|
@ -516,6 +518,10 @@ fn update_sound_properties(mut query: Query<&mut Sound>) {
|
|||
.pitch_bend()
|
||||
.set(pitch)
|
||||
.expect("Failed to set pitch");
|
||||
if let Some(generator) = generator
|
||||
.cast_to::<syz::BufferGenerator>()
|
||||
.expect("Failed to cast")
|
||||
{
|
||||
generator
|
||||
.looping()
|
||||
.set(looping)
|
||||
|
@ -523,6 +529,7 @@ fn update_sound_properties(mut query: Query<&mut Sound>) {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn update_source_playback_state(query: Query<&Source>) {
|
||||
for source in &query {
|
||||
|
|
Loading…
Reference in New Issue
Block a user