70 lines
1.4 KiB
Rust
70 lines
1.4 KiB
Rust
use bevy::prelude::*;
|
|
|
|
fn main() {
|
|
App::new() //
|
|
.add_plugins(DefaultPlugins)
|
|
.add_systems(PreStartup, pre_startup)
|
|
.add_systems(Startup, (startup, setup))
|
|
.add_systems(PostStartup, post_startup)
|
|
.add_systems(First, first)
|
|
.add_systems(PreUpdate, pre_update)
|
|
.add_systems(Update, (update, check_space_pressed))
|
|
.add_systems(PostUpdate, post_update)
|
|
.run();
|
|
}
|
|
|
|
fn pre_startup() {
|
|
info!("PreStartup");
|
|
}
|
|
|
|
fn startup() {
|
|
info!("Startup");
|
|
}
|
|
|
|
fn post_startup() {
|
|
info!("PostStartup");
|
|
}
|
|
|
|
fn first() {
|
|
info!("First");
|
|
}
|
|
|
|
fn pre_update() {
|
|
info!("PreUpdate");
|
|
}
|
|
|
|
fn update() {
|
|
info!("Update");
|
|
}
|
|
|
|
fn post_update() {
|
|
info!("PostUpdate");
|
|
}
|
|
|
|
fn check_space_pressed(input: Res<ButtonInput<KeyCode>>, mut commands: Commands) {
|
|
if input.just_pressed(KeyCode::Space) {
|
|
commands.trigger(TestEvent0);
|
|
}
|
|
}
|
|
|
|
fn setup(mut commands: Commands) {
|
|
commands.spawn((Observer::new(test_event_0_handler),));
|
|
commands.spawn((Observer::new(test_event_1_handler),));
|
|
}
|
|
|
|
#[derive(Event, Debug)]
|
|
struct TestEvent0;
|
|
|
|
#[derive(Event, Debug)]
|
|
struct TestEvent1;
|
|
|
|
fn test_event_0_handler(event: On<TestEvent0>, mut commands: Commands) {
|
|
info!("handle {:?}", event.event());
|
|
commands.trigger(TestEvent1);
|
|
}
|
|
|
|
fn test_event_1_handler(event: On<TestEvent1>, mut commands: Commands) {
|
|
info!("handle {:?}", event.event());
|
|
commands.trigger(TestEvent0);
|
|
}
|