Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a generic systems example to the examples folder in bevy. #2191

Closed
wants to merge 8 commits into from
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,10 @@ path = "examples/ecs/timers.rs"
name = "query_bundle"
path = "examples/ecs/query_bundle.rs"

[[example]]
name = "generic_systems"
path = "examples/ecs/generic_systems.rs"

# Games
[[example]]
name = "alien_cake_addict"
Expand Down
27 changes: 27 additions & 0 deletions examples/ecs/generic_systems.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
use bevy::prelude::*;
use bevy::ecs::component::Component;
AmrDhaliwal marked this conversation as resolved.
Show resolved Hide resolved

struct A;
struct B;

pub fn spawn_entities<T: Component>(mut commands: Commands,
AmrDhaliwal marked this conversation as resolved.
Show resolved Hide resolved
mouse_button_inputs: Res<Input<MouseButton>>,) {
for _ in 0..10 {
let id = commands.spawn().insert(T).id();
if !mouse_button_inputs.just_pressed(MouseButton::Left) {
AmrDhaliwal marked this conversation as resolved.
Show resolved Hide resolved
return info!("Spawned entity {:?} with component {}", id, std::any::type_name::<T>());
}
if !mouse_button_inputs.just_pressed(MouseButton::Right) {
AmrDhaliwal marked this conversation as resolved.
Show resolved Hide resolved
return info!("Spawned entity {:?} with component {}", id, std::any::type_name::<T>());
}
}
}


fn main() {
App::build()
.add_plugins(DefaultPlugins)
.add_system(spawn_entities::<A>.system())
.add_system(spawn_entities::<B>.system())
.run();
}