You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
66 lines
1.9 KiB
Rust
66 lines
1.9 KiB
Rust
///
|
|
/// TODO: Custom Asset: FmodEventMapper
|
|
///
|
|
use crate::prelude::*;
|
|
use bevy_fmod::prelude::AudioSource;
|
|
use bevy_fmod::prelude::*;
|
|
|
|
pub(crate) struct AudioPlugin;
|
|
|
|
impl Plugin for AudioPlugin {
|
|
fn build(&self, app: &mut App) {
|
|
app.add_event::<AudioEvent>();
|
|
|
|
#[cfg(feature = "fmod")]
|
|
app.add_plugins(FmodPlugin {
|
|
audio_banks_paths: &[
|
|
"./assets/audio/Martian Chess Audio/Build/Desktop/Master.bank",
|
|
"./assets/audio/Martian Chess Audio/Build/Desktop/Master.strings.bank",
|
|
"./assets/audio/Martian Chess Audio/Build/Desktop/Music.bank",
|
|
"./assets/audio/Martian Chess Audio/Build/Desktop/SFX.bank",
|
|
],
|
|
});
|
|
|
|
app.add_systems(OnExit(GameState::Loading), play_background);
|
|
app.add_systems(
|
|
Update,
|
|
(
|
|
play_audio.run_if(any_component_added::<AudioSource>),
|
|
audio_trigger.run_if(on_event::<AudioEvent>()),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
#[derive(Event)]
|
|
pub enum AudioEvent {
|
|
MenuSelect,
|
|
PickUp,
|
|
PutDown,
|
|
}
|
|
|
|
fn play_background(studio: Res<FmodStudio>, mut commands: Commands) {
|
|
commands.spawn(AudioSource::new(
|
|
studio.0.get_event("event:/Music/Main Track").unwrap(),
|
|
));
|
|
}
|
|
|
|
fn play_audio(mut events: Query<&AudioSource, Added<AudioSource>>) {
|
|
events.iter_mut().for_each(|aud| aud.play());
|
|
}
|
|
|
|
fn audio_trigger(
|
|
mut events: EventReader<AudioEvent>,
|
|
studio: Res<FmodStudio>,
|
|
mut commands: Commands,
|
|
) {
|
|
events.iter().for_each(|event| {
|
|
let aud = match event {
|
|
AudioEvent::MenuSelect => studio.0.get_event("event:/SFX/MenuSelect"),
|
|
AudioEvent::PickUp => studio.0.get_event("event:/SFX/PickUpPiece"),
|
|
AudioEvent::PutDown => studio.0.get_event("event:/SFX/PutDownPiece"),
|
|
};
|
|
commands.spawn(AudioSource::new(aud.unwrap()));
|
|
})
|
|
}
|