Crate bevy_spawn_fn

Source
Expand description

§bevy_spawn_fn

Awesome spawning experience for bevy.

§Getting Started

Annotate your system with #[spawner_system], then use the spawn! macro.

#[spawner_system]
pub fn particle_emitter(emitter: Res<ParticleEmitter>) {
    if emitter.should_spawn() {
        spawn! {
            ParticleBundle {
                color: Color::Green,
                size: 10.0,
                texture: @load "images/my_image.png"
            }
        }
    }
}

If the function not a system, use the #[spawner_fn] macro, which takes less liberty in rewriting the function.

§The spawn! macro

spawn! spawns a IntoSpawnable and return an Entity.

The macro uses the infer_construct! macro from the default_constructor crate under the hood, which uses the InferInto trait for conversion.

Additionally effect @load can be used to load Handle<T> from a string path and @asset can be used to convert impl Into<T> to Handle<T> via AssetServer.

§The Spawnable Trait

Spawnable is a superset of Bundle that can be implemented to spawn heterogenous bundles and children.

IntoSpawnable is free ergonomics on top of Spawnable!

§Versions

bevybevy_spawn_fn
0.13latest

§License

License under either of

Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0) MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT) at your option.

§Contribution

Contributions are welcome!

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Macros§

spawn
Spawn a IntoSpawnable using a thread local spawner, returns Entity.

Structs§

AddMe
Component that immediately removes itself, adds the underlying value to Assets<T> and inserts a Handle<T>.
LoadMe
Component that immediately removes itself, loads the underlying path and inserts a Handle<T>.

Enums§

EntityMutSpawner
Mutable reference to an Entity.
Spawner
All types that can spawn Bundles.

Traits§

AsSpawner
A type that can spawn Bundles.
InferInto
Into with relaxed orphan rule, you can define non-owned conversion with a owned Marker. Keep in mind this inference will fail if multiple conversion paths are found.
IntoBundle
A type that can be converted into a Bundle.
IntoSpawnable
A type that can be converted to a Spawnable.
ScopedEntityMut
A global dynamic spawner.
ScopedSpawner
A global dynamic spawner.
SpawnChildScope
Create a function scope that can use spawn! to create children.
Spawnable
A type that can be spawned as an entity.

Functions§

asset_server_scope
Push a AssetServer onto thread local storage in a scope.
spawn
Spawn a IntoSpawnable using the current thread local spawner_scope.
spawner_scope
Push a Spawner onto thread local storage in a scope.

Attribute Macros§

spawner_fn
Make a function support the spawn! macro.
spawner_system
Make a system function support the spawn! macro.