load head sounds via asset_loader
This commit is contained in:
@@ -18,6 +18,8 @@ pub struct AudioAssets {
|
||||
pub cash: Handle<AudioSource>,
|
||||
#[asset(path = "sfx/hit", collection(typed))]
|
||||
pub hit: Vec<Handle<AudioSource>>,
|
||||
#[asset(path = "sfx/heads", collection(mapped, typed))]
|
||||
pub head: HashMap<AssetFileName, Handle<AudioSource>>,
|
||||
}
|
||||
|
||||
#[derive(AssetCollection, Resource)]
|
||||
|
||||
@@ -10,6 +10,7 @@ use crate::{
|
||||
heads_ui::HeadChanged,
|
||||
loading_assets::GameAssets,
|
||||
physics_layers::GameLayer,
|
||||
sounds::PlaySound,
|
||||
tb_entities::SpawnPoint,
|
||||
};
|
||||
use avian3d::{
|
||||
@@ -266,11 +267,7 @@ fn update_head(
|
||||
|
||||
let head_str = head_id_to_str(trigger.0);
|
||||
|
||||
//TODO: use asset loader
|
||||
commands.spawn((
|
||||
AudioPlayer::new(asset_server.load(format!("sfx/heads/{}.ogg", head_str))),
|
||||
PlaybackSettings::DESPAWN,
|
||||
));
|
||||
commands.trigger(PlaySound::Head(head_str.to_string()));
|
||||
|
||||
let mesh = asset_server
|
||||
.load(GltfAssetLabel::Scene(0).from_asset(format!("models/heads/{}.glb", head_str)));
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
use crate::loading_assets::AudioAssets;
|
||||
use bevy::prelude::*;
|
||||
|
||||
use crate::loading_assets::AudioAssets;
|
||||
|
||||
#[derive(Event, Copy, Clone, Debug)]
|
||||
#[derive(Event, Clone, Debug)]
|
||||
pub enum PlaySound {
|
||||
Hit,
|
||||
KeyCollect,
|
||||
Gun,
|
||||
Gate,
|
||||
CashCollect,
|
||||
Head(String),
|
||||
}
|
||||
|
||||
pub fn plugin(app: &mut App) {
|
||||
@@ -37,6 +37,14 @@ fn spawn_sounds(
|
||||
PlaySound::Gun => assets.gun.clone(),
|
||||
PlaySound::Gate => assets.gate.clone(),
|
||||
PlaySound::CashCollect => assets.cash.clone(),
|
||||
PlaySound::Head(name) => {
|
||||
let filename = format!("{}.ogg", name);
|
||||
assets
|
||||
.head
|
||||
.get(filename.as_str())
|
||||
.expect(format!("invalid head '{}'", filename).as_str())
|
||||
.clone()
|
||||
}
|
||||
};
|
||||
|
||||
commands.spawn((
|
||||
|
||||
Reference in New Issue
Block a user