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() .insert(Listener) .insert(Transform::default()) .insert(RotationTimer::default()); let handle = handles.sounds[0].clone(); let buffer = asset_server.get_handle(handle); commands .spawn() .insert(Transform::from_translation(Vec3::new(45., 0., 0.))) .insert(Sound { buffer, looping: true, ..default() }); } } fn rotate_listener(time: Res