Make the component types of the new animation players clonable. (#13736)
# Objective Some use cases might require holding onto the previous state of the animation player for change detection. ## Solution Added `clone` and `copy` implementation to most animation types. Added optimized `clone_from` implementations for the specific use case of holding a `PreviousAnimationPlayer` component. --------- Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
This commit is contained in:
parent
c71fa76f12
commit
4df95384ba
@ -236,7 +236,7 @@ impl Hash for AnimationTargetId {
|
|||||||
/// Note that each entity can only be animated by one animation player at a
|
/// Note that each entity can only be animated by one animation player at a
|
||||||
/// time. However, you can change [`AnimationTarget`]'s `player` property at
|
/// time. However, you can change [`AnimationTarget`]'s `player` property at
|
||||||
/// runtime to change which player is responsible for animating the entity.
|
/// runtime to change which player is responsible for animating the entity.
|
||||||
#[derive(Clone, Component, Reflect)]
|
#[derive(Clone, Copy, Component, Reflect)]
|
||||||
#[reflect(Component, MapEntities)]
|
#[reflect(Component, MapEntities)]
|
||||||
pub struct AnimationTarget {
|
pub struct AnimationTarget {
|
||||||
/// The ID of this animation target.
|
/// The ID of this animation target.
|
||||||
@ -326,7 +326,7 @@ pub enum RepeatAnimation {
|
|||||||
/// playing, but is presently paused.
|
/// playing, but is presently paused.
|
||||||
///
|
///
|
||||||
/// An stopped animation is considered no longer active.
|
/// An stopped animation is considered no longer active.
|
||||||
#[derive(Debug, Reflect)]
|
#[derive(Debug, Clone, Copy, Reflect)]
|
||||||
pub struct ActiveAnimation {
|
pub struct ActiveAnimation {
|
||||||
/// The factor by which the weight from the [`AnimationGraph`] is multiplied.
|
/// The factor by which the weight from the [`AnimationGraph`] is multiplied.
|
||||||
weight: f32,
|
weight: f32,
|
||||||
@ -515,6 +515,21 @@ pub struct AnimationPlayer {
|
|||||||
blend_weights: HashMap<AnimationNodeIndex, f32>,
|
blend_weights: HashMap<AnimationNodeIndex, f32>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This is needed since `#[derive(Clone)]` does not generate optimized `clone_from`.
|
||||||
|
impl Clone for AnimationPlayer {
|
||||||
|
fn clone(&self) -> Self {
|
||||||
|
Self {
|
||||||
|
active_animations: self.active_animations.clone(),
|
||||||
|
blend_weights: self.blend_weights.clone(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn clone_from(&mut self, source: &Self) {
|
||||||
|
self.active_animations.clone_from(&source.active_animations);
|
||||||
|
self.blend_weights.clone_from(&source.blend_weights);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// The components that we might need to read or write during animation of each
|
/// The components that we might need to read or write during animation of each
|
||||||
/// animation target.
|
/// animation target.
|
||||||
struct AnimationTargetContext<'a> {
|
struct AnimationTargetContext<'a> {
|
||||||
|
@ -33,8 +33,23 @@ pub struct AnimationTransitions {
|
|||||||
transitions: Vec<AnimationTransition>,
|
transitions: Vec<AnimationTransition>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This is needed since `#[derive(Clone)]` does not generate optimized `clone_from`.
|
||||||
|
impl Clone for AnimationTransitions {
|
||||||
|
fn clone(&self) -> Self {
|
||||||
|
Self {
|
||||||
|
main_animation: self.main_animation,
|
||||||
|
transitions: self.transitions.clone(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn clone_from(&mut self, source: &Self) {
|
||||||
|
self.main_animation = source.main_animation;
|
||||||
|
self.transitions.clone_from(&source.transitions);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// An animation that is being faded out as part of a transition
|
/// An animation that is being faded out as part of a transition
|
||||||
#[derive(Debug, Reflect)]
|
#[derive(Debug, Clone, Copy, Reflect)]
|
||||||
pub struct AnimationTransition {
|
pub struct AnimationTransition {
|
||||||
/// The current weight. Starts at 1.0 and goes to 0.0 during the fade-out.
|
/// The current weight. Starts at 1.0 and goes to 0.0 during the fade-out.
|
||||||
current_weight: f32,
|
current_weight: f32,
|
||||||
|
Loading…
Reference in New Issue
Block a user