use bevy::prelude::*; use bevy_ui_navigation::events::{Direction, NavRequest}; use bevy_ui_navigation::prelude::{ DefaultNavigationPlugins, FocusState, Focusable, NavRequestSystem, }; use bevy_ui_navigation::systems::InputMapping; /// This example shows what happens when there is a lot of focusables on screen. /// It doesn't run well on debug builds, you should try running it with the `--release` /// flag. /// /// It is very useful to assess the performance of bevy ui and how expansive our systems /// are. /// /// You can toggle automatic generation of NavRequest with the `K` key. fn main() { App::new() .add_plugins((DefaultPlugins, DefaultNavigationPlugins)) .add_systems(Startup, setup) .add_systems( Update, ( non_stop_move.before(NavRequestSystem), button_system.after(NavRequestSystem), ), ) .run(); } #[derive(Component)] struct IdleColor(BackgroundColor); fn button_system( mut interaction_query: Query< (&Focusable, &mut BackgroundColor, &IdleColor), Changed, >, ) { for (focusable, mut material, IdleColor(idle_color)) in interaction_query.iter_mut() { if let FocusState::Focused = focusable.state() { *material = Color::ORANGE_RED.into(); } else { *material = *idle_color; } } } struct MyDirection(Direction); impl Default for MyDirection { fn default() -> Self { Self(Direction::South) } } fn non_stop_move( input: Res>, mut requests: EventWriter, mut enabled: Local, time: Res