diff --git a/crates/bevy_ecs/src/schedule/state.rs b/crates/bevy_ecs/src/schedule/state.rs index 4f9d9c38bccd1..c5a7b547508d4 100644 --- a/crates/bevy_ecs/src/schedule/state.rs +++ b/crates/bevy_ecs/src/schedule/state.rs @@ -31,16 +31,35 @@ pub use bevy_ecs_macros::States; /// # Example /// /// ``` -/// use bevy_ecs::prelude::States; -/// +/// # use bevy_ecs::prelude::States; /// #[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 {}