also load animations via asset loader

This commit is contained in:
2025-03-26 21:24:56 +08:00
parent 91e5435c64
commit 540843c5a4
2 changed files with 18 additions and 11 deletions

View File

@@ -1,10 +1,7 @@
use crate::{GameState, loading_assets::GameAssets};
use bevy::prelude::*; use bevy::prelude::*;
use std::time::Duration; use std::time::Duration;
use crate::GameState;
pub const ALIEN_ASSET_PATH: &str = "models/alien_naked.glb";
#[derive(Resource)] #[derive(Resource)]
pub struct Animations { pub struct Animations {
pub animations: Vec<AnimationNodeIndex>, pub animations: Vec<AnimationNodeIndex>,
@@ -21,14 +18,14 @@ pub fn plugin(app: &mut App) {
fn setup( fn setup(
mut commands: Commands, mut commands: Commands,
asset_server: Res<AssetServer>, assets: Res<GameAssets>,
mut graphs: ResMut<Assets<AnimationGraph>>, mut graphs: ResMut<Assets<AnimationGraph>>,
) { ) {
// Build the animation graph // Build the animation graph
let (graph, node_indices) = AnimationGraph::from_clips([ let (graph, node_indices) = AnimationGraph::from_clips([
asset_server.load(GltfAssetLabel::Animation(2).from_asset(ALIEN_ASSET_PATH)), assets.animations_alien.get("Animation2").cloned().unwrap(),
asset_server.load(GltfAssetLabel::Animation(1).from_asset(ALIEN_ASSET_PATH)), assets.animations_alien.get("Animation1").cloned().unwrap(),
asset_server.load(GltfAssetLabel::Animation(0).from_asset(ALIEN_ASSET_PATH)), assets.animations_alien.get("Animation0").cloned().unwrap(),
]); ]);
// Insert a resource with the current scene information // Insert a resource with the current scene information

View File

@@ -1,5 +1,5 @@
use crate::GameState; use crate::GameState;
use bevy::prelude::*; use bevy::{prelude::*, utils::HashMap};
use bevy_asset_loader::prelude::*; use bevy_asset_loader::prelude::*;
#[derive(AssetCollection, Resource)] #[derive(AssetCollection, Resource)]
@@ -49,11 +49,21 @@ pub struct GameAssets {
#[asset(path = "models/spawn.glb#Scene0")] #[asset(path = "models/spawn.glb#Scene0")]
pub mesh_spawn: Handle<Scene>, pub mesh_spawn: Handle<Scene>,
#[asset(path = "models/cash.glb#Scene0")]
pub mesh_cash: Handle<Scene>,
#[asset(path = "models/alien_naked.glb#Scene0")] #[asset(path = "models/alien_naked.glb#Scene0")]
pub mesh_alien: Handle<Scene>, pub mesh_alien: Handle<Scene>,
#[asset(path = "models/cash.glb#Scene0")] #[asset(
pub mesh_cash: Handle<Scene>, paths(
"models/alien_naked.glb#Animation0",
"models/alien_naked.glb#Animation1",
"models/alien_naked.glb#Animation2",
),
collection(mapped, typed)
)]
pub animations_alien: HashMap<AssetLabel, Handle<AnimationClip>>,
} }
pub struct LoadingPlugin; pub struct LoadingPlugin;