mirror of
https://github.com/bevyengine/bevy
synced 2024-11-22 04:33:37 +00:00
Add a doctest example for EntityMapper (#11583)
# Objective Fixes: https://github.com/bevyengine/bevy/issues/11549 Add a doctest example of what a custom implementation of an `EntityMapper` would look like. (need to wait until https://github.com/bevyengine/bevy/pull/11428 is merged) --------- Co-authored-by: Charles Bournhonesque <cbournhonesque@snapchat.com> Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com> Co-authored-by: Hennadii Chernyshchyk <genaloner@gmail.com>
This commit is contained in:
parent
2bf481c03b
commit
b17d42dbe9
1 changed files with 19 additions and 0 deletions
|
@ -51,6 +51,25 @@ pub trait MapEntities {
|
|||
/// (mapper inputs) to the current world's entities (mapper outputs).
|
||||
///
|
||||
/// More generally, this can be used to map [`Entity`] references between any two [`Worlds`](World).
|
||||
///
|
||||
/// ## Example
|
||||
///
|
||||
/// ```
|
||||
/// # use bevy_ecs::entity::{Entity, EntityMapper};
|
||||
/// # use bevy_utils::EntityHashMap;
|
||||
/// #
|
||||
/// pub struct SimpleEntityMapper {
|
||||
/// map: EntityHashMap<Entity, Entity>,
|
||||
/// }
|
||||
///
|
||||
/// // Example implementation of EntityMapper where we map an entity to another entity if it exists
|
||||
/// // in the underlying `EntityHashMap`, otherwise we just return the original entity.
|
||||
/// impl EntityMapper for SimpleEntityMapper {
|
||||
/// fn map_entity(&mut self, entity: Entity) -> Entity {
|
||||
/// self.map.get(&entity).copied().unwrap_or(entity)
|
||||
/// }
|
||||
/// }
|
||||
/// ```
|
||||
pub trait EntityMapper {
|
||||
/// Map an entity to another entity
|
||||
fn map_entity(&mut self, entity: Entity) -> Entity;
|
||||
|
|
Loading…
Reference in a new issue