Make event example use a local resource (#754)
Make EventListenerState a local resource
This commit is contained in:
parent
e02bd9fde1
commit
ef86ce98ed
@ -7,7 +7,6 @@ fn main() {
|
||||
.add_default_plugins()
|
||||
.add_event::<MyEvent>()
|
||||
.init_resource::<EventTriggerState>()
|
||||
.init_resource::<EventListenerState>()
|
||||
.add_system(event_trigger_system.system())
|
||||
.add_system(event_listener_system.system())
|
||||
.run();
|
||||
@ -43,14 +42,12 @@ fn event_trigger_system(
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
struct EventListenerState {
|
||||
my_event_reader: EventReader<MyEvent>,
|
||||
}
|
||||
|
||||
// prints events as they come in
|
||||
fn event_listener_system(mut state: ResMut<EventListenerState>, my_events: Res<Events<MyEvent>>) {
|
||||
for my_event in state.my_event_reader.iter(&my_events) {
|
||||
fn event_listener_system(
|
||||
mut my_event_reader: Local<EventReader<MyEvent>>,
|
||||
my_events: Res<Events<MyEvent>>,
|
||||
) {
|
||||
for my_event in my_event_reader.iter(&my_events) {
|
||||
println!("{}", my_event.message);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user