use bevy::{ diagnostic::{DiagnosticsStore, FrameTimeDiagnosticsPlugin}, prelude::*, }; use crate::debug::DebugMode; pub(super) struct FpsCounterPlugin; impl Plugin for FpsCounterPlugin { fn build(&self, app: &mut App) { app.add_plugins(FrameTimeDiagnosticsPlugin) .add_systems(Startup, layout) .add_systems(Update, update) .add_systems( Update, update_visibility.run_if(resource_exists_and_changed::()), ); } } #[derive(Component)] struct FramerateCounter; fn layout(mut cmd: Commands) { let mut text_bundle = TextBundle::from_section( "0 fps", TextStyle { color: Color::GREEN, font_size: 14., ..default() }, ) .with_text_alignment(TextAlignment::Right) .with_style(Style { position_type: PositionType::Absolute, right: Val::Px(16.), bottom: Val::Px(16.), ..default() }); text_bundle.visibility = Visibility::Hidden; cmd.spawn(( FramerateCounter, Name::new("Framerate Counter"), text_bundle, )); } fn update( time: Res