no-camera
many_buttons
argument, only emit UI camera warnings once (#17557)
# Objective * Add a `no-camera` argument to the `many_buttons` stress test example. * Only emit the UI "no camera found" warnings once.
This commit is contained in:
parent
b039bf6768
commit
a80263a5bf
@ -12,6 +12,7 @@ use bevy_math::{UVec2, Vec2};
|
|||||||
use bevy_render::camera::{Camera, NormalizedRenderTarget};
|
use bevy_render::camera::{Camera, NormalizedRenderTarget};
|
||||||
use bevy_sprite::BorderRect;
|
use bevy_sprite::BorderRect;
|
||||||
use bevy_transform::components::Transform;
|
use bevy_transform::components::Transform;
|
||||||
|
use bevy_utils::once;
|
||||||
use bevy_window::{PrimaryWindow, Window, WindowScaleFactorChanged};
|
use bevy_window::{PrimaryWindow, Window, WindowScaleFactorChanged};
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
use tracing::warn;
|
use tracing::warn;
|
||||||
@ -164,10 +165,10 @@ pub fn ui_layout_system(
|
|||||||
match camera_with_default(target_camera) {
|
match camera_with_default(target_camera) {
|
||||||
Some(camera_entity) => {
|
Some(camera_entity) => {
|
||||||
let Ok((_, camera)) = cameras.get(camera_entity) else {
|
let Ok((_, camera)) = cameras.get(camera_entity) else {
|
||||||
warn!(
|
once!(warn!(
|
||||||
"UiTargetCamera (of root UI node {entity}) is pointing to a camera {} which doesn't exist",
|
"UiTargetCamera (of root UI node {entity}) is pointing to a camera {} which doesn't exist",
|
||||||
camera_entity
|
camera_entity
|
||||||
);
|
));
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
let layout_info = camera_layout_info
|
let layout_info = camera_layout_info
|
||||||
@ -177,13 +178,13 @@ pub fn ui_layout_system(
|
|||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
if cameras.is_empty() {
|
if cameras.is_empty() {
|
||||||
warn!("No camera found to render UI to. To fix this, add at least one camera to the scene.");
|
once!(warn!("No camera found to render UI to. To fix this, add at least one camera to the scene."));
|
||||||
} else {
|
} else {
|
||||||
warn!(
|
once!(warn!(
|
||||||
"Multiple cameras found, causing UI target ambiguity. \
|
"Multiple cameras found, causing UI target ambiguity. \
|
||||||
To fix this, add an explicit `UiTargetCamera` component to the root UI node {}",
|
To fix this, add an explicit `UiTargetCamera` component to the root UI node {}",
|
||||||
entity
|
entity
|
||||||
);
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -50,6 +50,10 @@ struct Args {
|
|||||||
/// set the root node to display none, removing all nodes from the layout.
|
/// set the root node to display none, removing all nodes from the layout.
|
||||||
#[argh(switch)]
|
#[argh(switch)]
|
||||||
display_none: bool,
|
display_none: bool,
|
||||||
|
|
||||||
|
/// spawn the layout without a camera
|
||||||
|
#[argh(switch)]
|
||||||
|
no_camera: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This example shows what happens when there is a lot of buttons on screen.
|
/// This example shows what happens when there is a lot of buttons on screen.
|
||||||
@ -82,9 +86,11 @@ fn main() {
|
|||||||
})
|
})
|
||||||
.add_systems(Update, (button_system, set_text_colors_changed));
|
.add_systems(Update, (button_system, set_text_colors_changed));
|
||||||
|
|
||||||
|
if !args.no_camera {
|
||||||
app.add_systems(Startup, |mut commands: Commands| {
|
app.add_systems(Startup, |mut commands: Commands| {
|
||||||
commands.spawn(Camera2d);
|
commands.spawn(Camera2d);
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if args.grid {
|
if args.grid {
|
||||||
app.add_systems(Startup, setup_grid);
|
app.add_systems(Startup, setup_grid);
|
||||||
|
Loading…
Reference in New Issue
Block a user