ability to enable or disable absm nodes
@@ -21,11 +21,24 @@ use crate::{
};
use std::ops::{Deref, DerefMut};
-#[derive(Visit, Reflect, Clone, Debug, Default)]
+#[derive(Visit, Reflect, Clone, Debug)]
pub struct AnimationBlendingStateMachine {
base: Base,
machine: InheritableVariable<Machine>,
animation_player: InheritableVariable<Handle<Node>>,
+ #[visit(optional)]
+ enabled: bool,
+}
+
+impl Default for AnimationBlendingStateMachine {
+ fn default() -> Self {
+ Self {
+ base: Default::default(),
+ machine: Default::default(),
+ animation_player: Default::default(),
+ enabled: true,
+ }
+ }
}
impl AnimationBlendingStateMachine {
@@ -48,6 +61,14 @@ impl AnimationBlendingStateMachine {
pub fn animation_player(&self) -> Handle<Node> {
*self.animation_player
}
+
+ pub fn set_enabled(&mut self, enabled: bool) {
+ self.enabled = enabled;
+ }
+
+ pub fn is_enabled(&self) -> bool {
+ self.enabled
+ }
}
impl TypeUuidProvider for AnimationBlendingStateMachine {
@@ -90,6 +111,7 @@ impl NodeTrait for AnimationBlendingStateMachine {
}
fn update(&mut self, context: &mut UpdateContext) -> bool {
+ if self.enabled {
if let Some(animation_player) = context
.nodes
.try_borrow_mut(*self.animation_player)
@@ -106,6 +128,7 @@ impl NodeTrait for AnimationBlendingStateMachine {
pose.apply_internal(context.nodes);
}
+ }
self.base.update_lifetime(context.dt)
}
@@ -131,6 +154,7 @@ pub struct AnimationBlendingStateMachineBuilder {
base_builder: BaseBuilder,
machine: Machine,
animation_player: Handle<Node>,
+ enabled: bool,
}
impl AnimationBlendingStateMachineBuilder {
@@ -139,6 +163,7 @@ impl AnimationBlendingStateMachineBuilder {
base_builder,
machine: Default::default(),
animation_player: Default::default(),
+ enabled: true,
}
}
@@ -152,11 +177,17 @@ impl AnimationBlendingStateMachineBuilder {
self
}
+ pub fn with_enabled(mut self, enabled: bool) -> Self {
+ self.enabled = enabled;
+ self
+ }
+
pub fn build_node(self) -> Node {
Node::new(AnimationBlendingStateMachine {
base: self.base_builder.build_base(),
machine: self.machine.into(),
animation_player: self.animation_player.into(),
+ enabled: self.enabled,
})
}
