Debug rect

This commit is contained in:
Franklin 2023-11-08 11:36:04 -04:00
parent 86909e8bcb
commit 28765e173a
4 changed files with 36 additions and 6 deletions

31
src/ui/editor/camera.rs Normal file
View File

@ -0,0 +1,31 @@
use bevy::{prelude::*, window::PrimaryWindow, render::camera::Viewport};
use bevy_inspector_egui::bevy_egui;
use crate::comps::core::markers::camera::MainCamera;
pub fn set_camera_viewport(
primary_window: Query<&mut Window, With<PrimaryWindow>>,
egui_settings: Res<bevy_egui::EguiSettings>,
mut cameras: Query<&mut Camera, With<MainCamera>>,
) {
let Ok(mut cam) = cameras.get_single_mut() else {
return;
};
let Ok(window) = primary_window.get_single() else {
return;
};
println!("{}, {}", window.width(), window.height());
let scale_factor = window.scale_factor() * egui_settings.scale_factor;
/*let viewport_pos = ui_state.viewport_rect.left_top().to_vec2() * scale_factor as f32;
let viewport_size = ui_state.viewport_rect.size() * scale_factor as f32;
cam.viewport = Some(Viewport {
physical_position: UVec2::new(viewport_pos.x as u32, viewport_pos.y as u32),
physical_size: UVec2::new(viewport_size.x as u32, viewport_size.y as u32),
depth: 0.0..1.0,
});*/
}

View File

@ -2,3 +2,4 @@
pub mod plugin;
pub mod panels;
pub mod state;
pub mod camera;

View File

@ -20,15 +20,13 @@ pub fn editor_ui(
.show(egui_context.get_mut(), |ui| {
egui::ScrollArea::vertical().show(ui, |ui| {
ui.heading("Components Hierarchy");
bevy_inspector_egui::bevy_inspector::hierarchy::hierarchy_ui(
world,
ui,
&mut selected_entities,
);
println!("{:#?}", ui.clip_rect());
ui.separator();
ui.heading("All Resources");
bevy_inspector_egui::bevy_inspector::ui_for_resources(world, ui);
ui.allocate_rect(ui.available_rect_before_wrap(), egui::Sense::hover());
@ -41,7 +39,6 @@ pub fn editor_ui(
.show(egui_context.get_mut(), |ui| {
egui::ScrollArea::vertical().show(ui, |ui| {
ui.heading("Inspector");
match selected_entities.as_slice() {
&[entity] => {
bevy_inspector_egui::bevy_inspector::ui_for_entity(world, entity, ui);

View File

@ -2,7 +2,7 @@ use bevy::prelude::*;
use crate::{logic::core::{guns::{player_firing::PlayerFiringInfo, caliber::Caliber, firearm::Firearm, spray_pattern::FirearmSprayPattern}, player::{player_values_state::PlayerValuesState, camera_player_sync::MouseMovementSettings, player_movement::{PlayerLinearYState, PlayerLinearXZState, PlayerMovementInput}}}, comps::core::markers::{firearm::{FirearmData, MagazineData}, holdable::{HoldableObjectData, InPlayerHands}, player::{PlayerData, Player, PlayerHand}}, scenes::scene1::skybox::Cubemap, setup::{animations::{AllFirearmAnimations, FirearmAnimations}, assets::{GltfAssetType, GltfAssets}, equipment::Equipment, load_state::GameLoadState}};
use super::{panels::editor_ui, state::EditorUiState};
use super::{panels::editor_ui, state::EditorUiState, camera::set_camera_viewport};
pub struct MainEditorUiPlugin;
@ -34,5 +34,6 @@ impl Plugin for MainEditorUiPlugin {
.register_type::<GameLoadState>();
app.insert_resource(EditorUiState::new());
app.add_systems(Update, editor_ui);
app.add_systems(PostUpdate, set_camera_viewport);
}
}