-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhello_state_machine.rs
35 lines (30 loc) · 982 Bytes
/
hello_state_machine.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
//! Behaviors in state machines can be triggered
//! by multiple sources from arbitary positions in a graph.
//! In beet this is achieved using the [`RunOnRunResult`] action.
use beet::prelude::*;
use beet_examples::prelude::*;
use bevy::prelude::*;
#[rustfmt::skip]
fn main() {
let mut app = App::new();
app.insert_resource(BeetDebugConfig::default())
.add_plugins(minimal_beet_example_plugin);
let world = app.world_mut();
let state2 = world.spawn((
Name::new("state2"),
EndOnRun::success(),
)).id();
// transitions are just behaviors that always trigger the next behavior
let transition = world.spawn((
Name::new("transition"),
EndOnRun::success(),
RunOnRunResult::new_with_target(state2),
)).id();
world.spawn((
Name::new("state1"),
EndOnRun::success(),
// here RunOnRunResult can be swapped out with a control flow action
// that decides which state to go to next
RunOnRunResult::new_with_target(transition),
)).flush_trigger(OnRun);
}