From 94cd97b2abdea24b4694fbcfa73c0f3dbd4a156a Mon Sep 17 00:00:00 2001 From: Stepan Koltsov Date: Fri, 24 Nov 2023 00:28:35 +0000 Subject: [PATCH] Example how to update state --- crates/bevy_ecs/src/schedule/state.rs | 30 ++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/crates/bevy_ecs/src/schedule/state.rs b/crates/bevy_ecs/src/schedule/state.rs index a39f8cc036d1d..95595b87796c1 100644 --- a/crates/bevy_ecs/src/schedule/state.rs +++ b/crates/bevy_ecs/src/schedule/state.rs @@ -29,16 +29,36 @@ pub use bevy_ecs_macros::States; /// # Example /// /// ```rust -/// use bevy_ecs::prelude::States; +/// # use bevy_ecs::prelude::*; /// /// #[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, Default, States)] /// enum GameState { -/// #[default] -/// MainMenu, -/// SettingsMenu, -/// InGame, +/// #[default] +/// MainMenu, +/// SettingsMenu, +/// InGame, /// } /// +/// fn handle_escape_pressed(mut next_state: ResMut>) { +/// # let escape_pressed = true; +/// if escape_pressed { +/// next_state.set(GameState::SettingsMenu); +/// } +/// } +/// +/// fn open_settings_menu() { +/// // Show the settings menu... +/// } +/// +/// # struct AppMock; +/// # impl AppMock { +/// # fn add_systems(&mut self, schedule: S, systems: impl IntoSystemConfigs) {} +/// # } +/// # struct Update; +/// # let mut app = AppMock; +/// +/// app.add_systems(Update, handle_escape_pressed.run_if(in_state(GameState::MainMenu))); +/// app.add_systems(OnEnter(GameState::SettingsMenu), open_settings_menu); /// ``` pub trait States: 'static + Send + Sync + Clone + PartialEq + Eq + Hash + Debug + Default {}