bevy14: fix suit animation
This commit is contained in:
parent
a14dbcb5c7
commit
21a800942e
|
@ -12,6 +12,7 @@
|
|||
|
||||
use crate::prelude::*;
|
||||
use bevy::prelude::*;
|
||||
use std::time::Duration;
|
||||
|
||||
pub struct VisualPlugin;
|
||||
|
||||
|
@ -57,13 +58,36 @@ pub struct SpawnEffectEvent {
|
|||
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 {
|
||||
ew_effect.send(SpawnEffectEvent {
|
||||
class: Effects::FadeIn(Color::BLACK),
|
||||
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
|
||||
// commands.spawn((
|
||||
// BlackOutOverlay,
|
||||
|
@ -157,12 +181,17 @@ pub fn update_fadeout(
|
|||
}
|
||||
|
||||
fn play_animations(
|
||||
mut players: Query<&mut AnimationPlayer, Added<AnimationPlayer>>,
|
||||
asset_server: Res<AssetServer>,
|
||||
mut commands: Commands,
|
||||
mut players: Query<(Entity, &mut AnimationPlayer), Added<AnimationPlayer>>,
|
||||
suit_animation: Res<SuitAnimation>,
|
||||
) {
|
||||
for mut player in &mut players {
|
||||
let animation = asset_server.load("models/suit_v2/suit_v2.glb#Animation0");
|
||||
player.play(animation.clone()).repeat();
|
||||
for (entity, mut player) in &mut players {
|
||||
let mut transitions = AnimationTransitions::new();
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue