mirror of
https://github.com/bevyengine/bevy
synced 2024-11-21 20:23:28 +00:00
Add example demonstrating how to enable / disable diagnostics (#14741)
# Objective fixes #14569 ## Solution added an example to the diagnostic examples and linked the code to the docs of the diagnostic library itself. ## Testing I tested locally on my laptop in a web browser. Looked fine. You are able to collapse the whole "intro" part of the doc to get to the links sooner (for those who may think that including the example code here is annoying to scroll through) I would like people to run ```cargo doc``` and go the bevy_diagnostic page to see if they have any issues or suggestions. --- ## Showcase <img width="1067" alt="Screenshot 2024-08-14 at 12 52 16" src="https://github.com/user-attachments/assets/70b6c18a-0bb9-4656-ba53-c416f62c6116"> --------- Co-authored-by: dpeke <dpekelis@funstage.com>
This commit is contained in:
parent
5243fe6956
commit
eec38004a8
3 changed files with 42 additions and 0 deletions
11
Cargo.toml
11
Cargo.toml
|
@ -1604,6 +1604,17 @@ description = "Shows how to create a custom diagnostic"
|
|||
category = "Diagnostics"
|
||||
wasm = true
|
||||
|
||||
[[example]]
|
||||
name = "enabling_disabling_diagnostic"
|
||||
path = "examples/diagnostics/enabling_disabling_diagnostic.rs"
|
||||
doc-scrape-examples = true
|
||||
|
||||
[package.metadata.example.enabling_disabling_diagnostic]
|
||||
name = "Enabling/disabling diagnostic"
|
||||
description = "Shows how to disable/re-enable a Diagnostic during runtime"
|
||||
category = "Diagnostics"
|
||||
wasm = true
|
||||
|
||||
# ECS (Entity Component System)
|
||||
[[example]]
|
||||
name = "ecs_guide"
|
||||
|
|
|
@ -265,6 +265,7 @@ Example | Description
|
|||
Example | Description
|
||||
--- | ---
|
||||
[Custom Diagnostic](../examples/diagnostics/custom_diagnostic.rs) | Shows how to create a custom diagnostic
|
||||
[Enabling/disabling diagnostic](../examples/diagnostics/enabling_disabling_diagnostic.rs) | Shows how to disable/re-enable a Diagnostic during runtime
|
||||
[Log Diagnostics](../examples/diagnostics/log_diagnostics.rs) | Add a plugin that logs diagnostics, like frames per second (FPS), to the console
|
||||
|
||||
## ECS (Entity Component System)
|
||||
|
|
30
examples/diagnostics/enabling_disabling_diagnostic.rs
Normal file
30
examples/diagnostics/enabling_disabling_diagnostic.rs
Normal file
|
@ -0,0 +1,30 @@
|
|||
//! Shows how to disable/re-enable a Diagnostic during runtime
|
||||
|
||||
use std::time::Duration;
|
||||
|
||||
use bevy::{
|
||||
diagnostic::{DiagnosticsStore, FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin},
|
||||
prelude::*,
|
||||
time::common_conditions::on_timer,
|
||||
};
|
||||
|
||||
fn main() {
|
||||
App::new()
|
||||
.add_plugins((
|
||||
DefaultPlugins,
|
||||
FrameTimeDiagnosticsPlugin,
|
||||
LogDiagnosticsPlugin::default(),
|
||||
))
|
||||
.add_systems(
|
||||
Update,
|
||||
toggle.run_if(on_timer(Duration::from_secs_f32(10.0))),
|
||||
)
|
||||
.run();
|
||||
}
|
||||
|
||||
fn toggle(mut store: ResMut<DiagnosticsStore>) {
|
||||
for diag in store.iter_mut() {
|
||||
info!("toggling diagnostic {}", diag.path());
|
||||
diag.is_enabled = !diag.is_enabled;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue