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.
75 lines
2.2 KiB
Rust
75 lines
2.2 KiB
Rust
//! This example demonstrates how to use the FmodPlugin to play a sound.
|
|
//! Make sure to follow the instructions in the README.md to set up the demo project.
|
|
|
|
use bevy::prelude::*;
|
|
use bevy_fmod::prelude::AudioSource;
|
|
use bevy_fmod::prelude::*;
|
|
|
|
fn main() {
|
|
App::new()
|
|
.add_plugins((
|
|
DefaultPlugins,
|
|
FmodPlugin {
|
|
audio_banks_paths: &[
|
|
"./assets/audio/Martian Chess/Build/Desktop/Master.bank",
|
|
"./assets/audio/Martian Chess/Build/Desktop/Master.strings.bank",
|
|
"./assets/audio/Martian Chess/Build/Desktop/Music.bank",
|
|
],
|
|
},
|
|
))
|
|
.add_systems(Startup, startup)
|
|
.add_systems(PostStartup, play_music)
|
|
.run();
|
|
}
|
|
|
|
#[derive(Component)]
|
|
struct MyMusicPlayer;
|
|
|
|
fn startup(mut commands: Commands, studio: Res<FmodStudio>) {
|
|
let event_description = studio.0.get_event("event:/Martian Chess").unwrap();
|
|
|
|
studio
|
|
.0
|
|
.get_bank_list(10)
|
|
.expect("List banks")
|
|
.iter()
|
|
.for_each(|bank| {
|
|
info!("Bank: {:?}", bank.get_path().expect("Get bank path"));
|
|
bank.get_event_list(100)
|
|
.iter()
|
|
.flat_map(|events| events.iter())
|
|
.for_each(|event| {
|
|
info!("Event path: {:?}", event.get_path());
|
|
info!(
|
|
"Event parameter description {:?}",
|
|
event.get_parameter_description_by_name("Game State")
|
|
);
|
|
});
|
|
});
|
|
|
|
commands
|
|
.spawn(MyMusicPlayer)
|
|
.insert(AudioSource::new(event_description));
|
|
}
|
|
|
|
fn play_music(mut audio_sources: Query<&AudioSource, With<MyMusicPlayer>>) {
|
|
if let Ok(audio_source) = audio_sources.get_single_mut() {
|
|
audio_source.play();
|
|
|
|
info!(
|
|
"Parameter by name: {:?}",
|
|
audio_source
|
|
.event_instance
|
|
.get_parameter_by_name("Game State")
|
|
.expect("Get parameter")
|
|
);
|
|
match audio_source
|
|
.event_instance
|
|
.set_parameter_by_name("Game State", 5.0, true)
|
|
{
|
|
Ok(_) => (),
|
|
Err(e) => warn!("Error: {:?}", e),
|
|
};
|
|
}
|
|
}
|