tutorial: plugins
This commit is contained in:
parent
36724b9602
commit
6ed2169efe
20
src/main.rs
20
src/main.rs
|
@ -2,8 +2,7 @@ use bevy::prelude::*;
|
|||
|
||||
fn main() {
|
||||
App::new()
|
||||
.add_systems(Startup, add_people)
|
||||
.add_systems(Update, (hello_world, greet_people))
|
||||
.add_plugins((DefaultPlugins, HelloPlugin))
|
||||
.run();
|
||||
}
|
||||
|
||||
|
@ -19,6 +18,15 @@ fn add_people(mut commands: Commands) {
|
|||
commands.spawn((Person, Name("Zayna Nieves".to_string())));
|
||||
}
|
||||
|
||||
fn update_people(mut query: Query<&mut Name, With<Person>>) {
|
||||
for mut name in &mut query {
|
||||
if name.0 == "Elaina Proctor" {
|
||||
name.0 = "Elaina Hume".to_string();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn greet_people(query: Query<&Name, With<Person>>) {
|
||||
for name in &query {
|
||||
println!("hello {}!", name.0);
|
||||
|
@ -28,3 +36,11 @@ fn greet_people(query: Query<&Name, With<Person>>) {
|
|||
fn hello_world() {
|
||||
println!("hello world!");
|
||||
}
|
||||
|
||||
pub struct HelloPlugin;
|
||||
impl Plugin for HelloPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.add_systems(Startup, add_people)
|
||||
.add_systems(Update, (hello_world, (update_people, greet_people).chain()));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue