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., TimerMode::Repeating)) } } #[derive(Resource, 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(( TransformBundle::default(), Listener, RotationTimer::default(), )); let handle = handles.sounds[0].clone(); let buffer = asset_server.get_handle(handle); commands.spawn(( TransformBundle::from(Transform::from_translation(Vec3::new(10., 0., 0.))), Source::default(), Sound { audio: buffer.into(), looping: true, ..default() }, )); } } fn rotate_listener(time: Res