bevy14: fix suit animation

This commit is contained in:
yuni 2024-07-09 03:32:03 +02:00
parent a14dbcb5c7
commit 21a800942e

View file

@ -12,6 +12,7 @@
use crate::prelude::*; use crate::prelude::*;
use bevy::prelude::*; use bevy::prelude::*;
use std::time::Duration;
pub struct VisualPlugin; pub struct VisualPlugin;
@ -57,13 +58,36 @@ pub struct SpawnEffectEvent {
pub duration: f64, pub duration: f64,
} }
pub fn setup(settings: Res<var::Settings>, mut ew_effect: EventWriter<SpawnEffectEvent>) { #[derive(Resource)]
pub struct SuitAnimation {
index: AnimationNodeIndex,
graph: Handle<AnimationGraph>
}
pub fn setup(
settings: Res<var::Settings>,
asset_server: Res<AssetServer>,
mut commands: Commands,
mut ew_effect: EventWriter<SpawnEffectEvent>,
mut graphs: ResMut<Assets<AnimationGraph>>,
) {
if !settings.dev_mode { if !settings.dev_mode {
ew_effect.send(SpawnEffectEvent { ew_effect.send(SpawnEffectEvent {
class: Effects::FadeIn(Color::BLACK), class: Effects::FadeIn(Color::BLACK),
duration: 4.0, duration: 4.0,
}); });
} }
let mut graph = AnimationGraph::new();
let index = graph.add_clip(
asset_server.load(GltfAssetLabel::Animation(0).from_asset("models/suit_v2/suit_v2.glb")),
1.0,
graph.root,
);
let graph = graphs.add(graph);
commands.insert_resource(SuitAnimation { index, graph });
// Blackout disabled for now // Blackout disabled for now
// commands.spawn(( // commands.spawn((
// BlackOutOverlay, // BlackOutOverlay,
@ -157,12 +181,17 @@ pub fn update_fadeout(
} }
fn play_animations( fn play_animations(
mut players: Query<&mut AnimationPlayer, Added<AnimationPlayer>>, mut commands: Commands,
asset_server: Res<AssetServer>, mut players: Query<(Entity, &mut AnimationPlayer), Added<AnimationPlayer>>,
suit_animation: Res<SuitAnimation>,
) { ) {
for mut player in &mut players { for (entity, mut player) in &mut players {
let animation = asset_server.load("models/suit_v2/suit_v2.glb#Animation0"); let mut transitions = AnimationTransitions::new();
player.play(animation.clone()).repeat(); transitions
.play(&mut player, suit_animation.index, Duration::ZERO)
.repeat();
commands.entity(entity).insert(suit_animation.graph.clone()).insert(transitions);
//player.play(suit_ani_node_index.0).repeat();
} }
} }