AnimationTriggerType

Trait AnimationTriggerType 

Source
pub trait AnimationTriggerType:
    EntityEvent
    + Clone
    + Send
    + Sync
    + 'static
where Self::Trigger<'a>: for<'a> Default,
{ // Required methods fn trigger_name() -> &'static str; fn from_params(params: &HashMap<String, Value>) -> Option<Self>; }
Expand description

Trait for types that can be animation triggers.

Implement this trait to define custom type-safe trigger events that are automatically dispatched when a TriggerPayload::Custom with a matching event_name is encountered.

§Example

use bevy::prelude::*;
use bevy_map_animation::AnimationTriggerType;

#[derive(Event, Clone)]
pub struct AttackHitbox {
    pub damage: i32,
    pub knockback: f32,
}

impl AnimationTriggerType for AttackHitbox {
    fn trigger_name() -> &'static str { "attack_hitbox" }

    fn from_params(params: &std::collections::HashMap<String, serde_json::Value>) -> Option<Self> {
        Some(Self {
            damage: params.get("damage")?.as_i64()? as i32,
            knockback: params.get("knockback").and_then(|v| v.as_f64()).unwrap_or(5.0) as f32,
        })
    }
}

Required Methods§

Source

fn trigger_name() -> &'static str

The trigger name as used in the editor (matches TriggerPayload::Custom event_name)

Source

fn from_params(params: &HashMap<String, Value>) -> Option<Self>

Create an instance from the params HashMap. Return None if required params are missing or invalid.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§