forked from bevyengine/bevy
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add example demonstrating how to enable / disable diagnostics (bevyen…
…gine#14741) # Objective fixes bevyengine#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 <[email protected]>
- Loading branch information
1 parent
5243fe6
commit eec3800
Showing
3 changed files
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |