https://github.com/funatsufumiya/bevy_spawnable
tiny spawn utility for Bevy, to encapsulate spawn logic
https://github.com/funatsufumiya/bevy_spawnable
bevy-plugin
Last synced: 9 months ago
JSON representation
tiny spawn utility for Bevy, to encapsulate spawn logic
- Host: GitHub
- URL: https://github.com/funatsufumiya/bevy_spawnable
- Owner: funatsufumiya
- License: wtfpl
- Created: 2024-04-21T05:13:56.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-03-20T00:54:20.000Z (10 months ago)
- Last Synced: 2025-04-11T18:25:20.887Z (9 months ago)
- Topics: bevy-plugin
- Language: Rust
- Homepage:
- Size: 67.4 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# bevy_spawnable
[](https://crates.io/crates/bevy_spawnable)
[](https://docs.rs/bevy_spawnable)
[](LICENSE)
A tiny spawn utility for bevy. This crate will helps you:
- encapsulate the spawn logic into a single function or object.
- no worry about builder is `Commands` or `ChildBuilder`.
You can use this crate as a kind of like Unity's prefab as a code object, or builder to create entities which have complex structure.
( If you need more detailed spawn utility, consider [moonshine_spawn](https://github.com/Zeenobit/moonshine_spawn) as an alternative. )
## Usage
see [examples](examples)
### simple.rs
```rust
use bevy::{ecs::system::EntityCommands, prelude::*};
use bevy_spawnable::*;
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_systems(Startup, setup)
.run();
}
pub struct Hello {
pub text: String
}
impl Spawnable for Hello {
fn spawn<'a>(&mut self, builder: &'a mut impl GenericBuilder) -> EntityCommands<'a> {
let mut e = builder.spawn(Node {
width: Val::Percent(100.),
height: Val::Percent(100.),
flex_direction: FlexDirection::Column,
justify_content: JustifyContent::Center,
align_items: AlignItems::Center,
..default()
});
e.with_children(|root| {
bevy::prelude::ChildBuild::spawn(root, (
Text::new(self.text.clone()),
TextFont {
font_size: 50.0,
..default()
},
TextColor (
Color::WHITE.into()
),
TextLayout::new_with_justify(JustifyText::Center)
));
});
e
}}
fn setup(mut commands: Commands) {
commands.spawn(Camera2d::default());
commands.spawns(&mut Hello {
text: "Hello, Bevy!".to_string()
});
}
```
## Versions
| bevy | bevy_spawnable |
|------|---------------------|
| 0.15 | 0.3 |
| 0.14 | 0.2 |
| 0.13 | 0.1 |