mirror of
https://github.com/bevyengine/bevy
synced 2025-02-16 22:18:33 +00:00
Add remove bundle to bevy_ecs commands (#579)
add remove bundle to bevy_ecs commands
This commit is contained in:
parent
85a7f883d1
commit
74ad1c3752
1 changed files with 27 additions and 0 deletions
|
@ -112,6 +112,23 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
pub(crate) struct Remove<T>
|
||||
where
|
||||
T: Bundle + Send + Sync + 'static,
|
||||
{
|
||||
entity: Entity,
|
||||
phantom: PhantomData<T>,
|
||||
}
|
||||
|
||||
impl<T> WorldWriter for Remove<T>
|
||||
where
|
||||
T: Bundle + Send + Sync + 'static,
|
||||
{
|
||||
fn write(self: Box<Self>, world: &mut World) {
|
||||
world.remove::<T>(self.entity).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
pub trait ResourcesWriter: Send + Sync {
|
||||
fn write(self: Box<Self>, resources: &mut Resources);
|
||||
}
|
||||
|
@ -319,6 +336,16 @@ impl Commands {
|
|||
})
|
||||
}
|
||||
|
||||
pub fn remove<T>(&mut self, entity: Entity) -> &mut Self
|
||||
where
|
||||
T: Bundle + Send + Sync + 'static,
|
||||
{
|
||||
self.write_world(Remove::<T> {
|
||||
entity,
|
||||
phantom: PhantomData,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn set_entity_reserver(&self, entity_reserver: EntityReserver) {
|
||||
self.commands.lock().entity_reserver = Some(entity_reserver);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue