use std::f32; use bevy::{asset::LoadState, prelude::*}; use bevy_synthizer::*; #[derive(Component, Deref, DerefMut)] struct RotationTimer(Timer); impl Default for RotationTimer { fn default() -> Self { Self(Timer::from_seconds(30., true)) } } #[derive(Default)] struct AssetHandles { sounds: Vec, loaded: bool, } fn setup(asset_server: Res, mut handles: ResMut) { handles.sounds = asset_server.load_folder(".").expect("Failed to load sfx"); } fn load_and_create( mut commands: Commands, asset_server: Res, mut handles: ResMut, ) { if handles.loaded { return; } handles.loaded = asset_server .get_group_load_state(handles.sounds.iter().map(|handle| handle.id)) == LoadState::Loaded; if handles.loaded { commands .spawn_bundle(TransformBundle::default()) .insert(Listener) .insert(RotationTimer::default()); let handle = handles.sounds[0].clone(); let buffer = asset_server.get_handle(handle); commands .spawn_bundle(TransformBundle::from(Transform::from_translation( Vec3::new(10., 0., 0.), ))) .insert(Source::default()) .insert(Sound { buffer, looping: true, ..default() }); } } fn rotate_listener(time: Res