Skip to content

Commit

Permalink
Merge pull request #53 from rlidwka/camera-selection
Browse files Browse the repository at this point in the history
change camera handling in update_gizmos function
  • Loading branch information
urholaukkarinen authored Apr 15, 2024
2 parents 49b3588 + e34c51c commit 4dbedcb
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions crates/transform-gizmo-bevy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,25 @@ fn update_gizmos(

let scale_factor = window.scale_factor();

let Ok((camera, camera_transform)) = q_gizmo_camera.get_single() else {
bevy::log::warn!("Only one camera with a GizmoCamera component is supported.");
return;
let (camera, camera_transform) = {
let mut active_camera = None;

for camera in q_gizmo_camera.iter() {
if !camera.0.is_active {
continue;
}
if active_camera.is_some() {
// multiple active cameras found, warn and skip
bevy::log::warn!("Only one camera with a GizmoCamera component is supported.");
return;
}
active_camera = Some(camera);
}

match active_camera {
Some(camera) => camera,
None => return, // no active cameras in the scene
}
};

let Some(viewport) = camera.logical_viewport_rect() else {
Expand Down

0 comments on commit 4dbedcb

Please sign in to comment.