character hierarchy system param
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
use crate::{GameState, heads_database::HeadsDatabase, loading_assets::GameAssets};
|
||||
use bevy::{prelude::*, utils::HashMap};
|
||||
use bevy::{ecs::system::SystemParam, prelude::*, utils::HashMap};
|
||||
use std::time::Duration;
|
||||
|
||||
#[derive(Component, Debug)]
|
||||
@@ -8,6 +8,20 @@ pub struct ProjectileOrigin;
|
||||
#[derive(Component, Debug)]
|
||||
pub struct AnimatedCharacter(pub usize);
|
||||
|
||||
#[derive(SystemParam)]
|
||||
pub struct CharacterHierarchy<'w, 's> {
|
||||
descendants: Query<'w, 's, &'static Children>,
|
||||
projectile_origin: Query<'w, 's, &'static GlobalTransform, With<ProjectileOrigin>>,
|
||||
}
|
||||
|
||||
impl CharacterHierarchy<'_, '_> {
|
||||
pub fn projectile_origin(&self, entity: Entity) -> Option<&GlobalTransform> {
|
||||
self.descendants
|
||||
.iter_descendants(entity)
|
||||
.find_map(|child| self.projectile_origin.get(child).ok())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Component, Debug, Reflect)]
|
||||
#[reflect(Component)]
|
||||
pub struct CharacterAnimations {
|
||||
|
||||
Reference in New Issue
Block a user