Add remove bundle to bevy_ecs commands (#579)

add remove bundle to bevy_ecs commands
This commit is contained in:
Raymond 2020-09-26 14:27:56 -07:00 committed by GitHub
parent 85a7f883d1
commit 74ad1c3752
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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);
}