Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion crates/bevy_animation/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,13 +214,46 @@ impl Hash for AnimationTargetId {
#[reflect(Component, Clone)]
pub struct AnimatedBy(#[entities] pub Entity);

/// A read-only projection of an animation event.
///
/// Use this when you need to manually inspect or trigger animation events
/// outside of the standard animation playback system.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This kinda implies that this is a triggerable event, could be clearer

pub struct AnimationEventView {
/// The target bone or entity associated with the event.
/// [`None`] means no specific bone was targeted.
pub animation_target_id: Option<AnimationTargetId>,
/// The timestamp (in seconds) at which this event is configured to trigger.
pub trigger_time: f32,
/// The function that this animation event would run
pub trigger_fn: Arc<dyn Fn(&mut Commands, Entity, f32, f32) + Send + Sync>,
}

impl AnimationClip {
#[inline]
/// [`VariableCurve`]s for each animation target. Indexed by the [`AnimationTargetId`].
pub fn curves(&self) -> &AnimationCurves {
&self.curves
}

/// Returns an iterator over all animation events in this clip.
///
/// Generally should not be used unless existing animation events need to be manually triggered
/// for some reason.
///
/// The iterator yields [`AnimationEventView`], which provide access
/// to the target, timing, and trigger function of each event.
pub fn events_iter(&self) -> impl Iterator<Item = AnimationEventView> + '_ {
self.events.iter().flat_map(|(k, events)| {
let id = match k {
AnimationEventTarget::Root => None,
AnimationEventTarget::Node(node) => Some(*node),
};
events.iter().map(move |event| AnimationEventView {
animation_target_id: id,
trigger_time: event.time,
trigger_fn: event.event.trigger.0.clone(),
})
})
}
#[inline]
/// Get mutable references of [`VariableCurve`]s for each animation target. Indexed by the [`AnimationTargetId`].
pub fn curves_mut(&mut self) -> &mut AnimationCurves {
Expand Down
Loading