Struct hecs_hierarchy::TreeBuilder
source · [−]pub struct TreeBuilder<T> { /* private fields */ }
Expand description
Ergonomically construct trees without knowledge of world.
This struct builds the world using EntityBuilder
Example
use hecs_hierarchy::*;
use hecs::*;
struct Tree;
let mut world = World::default();
let mut builder = TreeBuilder::<Tree>::from(("root",));
builder.attach(("child 1",));
builder.attach({
let mut builder = TreeBuilder::new();
builder.add("child 2");
builder
});
let root = builder.spawn(&mut world);
assert_eq!(*world.get::<&'static str>(root).unwrap(), "root");
for (a, b) in world
.descendants_depth_first::<Tree>(root)
.zip(["child 1", "child 2"])
{
assert_eq!(*world.get::<&str>(a).unwrap(), b)
}
Implementations
Reserve the entity which this node will spawn
pub fn spawn_deferred(
&mut self,
world: &impl GenericWorld,
cmd: &mut CommandBuffer
) -> Entity
pub fn spawn_deferred(
&mut self,
world: &impl GenericWorld,
cmd: &mut CommandBuffer
) -> Entity
Spawn the whole tree into a commandbuffer. The world is required for reserving entities.
Add a bundle to the root
Atttach a new subtree
Consuming variant of Self::attach.
This is useful for nesting to alleviate the need to save an intermediate builder
Consuming variant of Self::attach_tree. This is useful for nesting to alleviate the need to save an intermediate builder
Get a reference to the deferred tree builder’s children.
Get a reference to the deferred tree builder’s root.
Get a mutable reference to the deferred tree builder’s root.
Trait Implementations
Performs the conversion.