40 lines
996 B
Rust
40 lines
996 B
Rust
|
use bevy::prelude::*;
|
||
|
|
||
|
#[derive(Component)]
|
||
|
pub struct ComponentBGM;
|
||
|
|
||
|
#[derive(Resource)]
|
||
|
struct SoundBGM(Handle<AudioSource>);
|
||
|
|
||
|
pub fn setup(
|
||
|
mut commands: Commands,
|
||
|
asset_server: Res<AssetServer>,
|
||
|
) {
|
||
|
let bgm = SoundBGM(asset_server.load("restricted/FTL - Faster Than Light (2012) OST - 12 - Void (Explore)-edQw2yYXQJM.ogg"));
|
||
|
commands.spawn((
|
||
|
AudioBundle {
|
||
|
source: bgm.0.clone(),
|
||
|
settings: PlaybackSettings::LOOP,
|
||
|
},
|
||
|
ComponentBGM,
|
||
|
));
|
||
|
commands.insert_resource(bgm);
|
||
|
commands.spawn((
|
||
|
AudioBundle {
|
||
|
source: asset_server.load("sounds/wakeup.ogg"),
|
||
|
settings: PlaybackSettings::DESPAWN,
|
||
|
},
|
||
|
));
|
||
|
}
|
||
|
|
||
|
pub fn toggle_bgm(
|
||
|
keyboard_input: Res<ButtonInput<KeyCode>>,
|
||
|
bgm_controller: Query<&AudioSink, With<ComponentBGM>>,
|
||
|
) {
|
||
|
if keyboard_input.just_pressed(KeyCode::KeyT) {
|
||
|
if let Ok(sink) = bgm_controller.get_single() {
|
||
|
sink.toggle()
|
||
|
}
|
||
|
}
|
||
|
}
|