ui/text example: Use a unit component to identify the target Text (#612)

This commit is contained in:
Zach Gotsch 2020-10-05 12:07:14 -07:00 committed by GitHub
parent 125afb41ac
commit d61a1735e9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -13,8 +13,11 @@ fn main() {
.run();
}
fn text_update_system(diagnostics: Res<Diagnostics>, mut query: Query<&mut Text>) {
for mut text in &mut query.iter() {
// A unit struct to help identify the FPS UI component, since there may be many Text components
struct FpsText;
fn text_update_system(diagnostics: Res<Diagnostics>, mut query: Query<(&mut Text, &FpsText)>) {
for (mut text, _tag) in &mut query.iter() {
if let Some(fps) = diagnostics.get(FrameTimeDiagnosticsPlugin::FPS) {
if let Some(average) = fps.average() {
text.value = format!("FPS: {:.2}", average);
@ -43,5 +46,6 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
},
},
..Default::default()
});
})
.with(FpsText);
}