-
Notifications
You must be signed in to change notification settings - Fork 75
Add OutlineGizmoPlugin and integrate outline gizmo functionality #195
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
824a3dc
f8dcb80
de5a01d
84b4a1b
5c35ea9
4190c0b
f4521b6
39a025d
4d84a97
886bf9b
a74f54a
cb5a7f5
d13350f
695b242
51e864b
77c8721
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
( | ||
entities: [ | ||
( | ||
components: [ | ||
(bevy_transform::components::Transform, ( | ||
translation: (1.0, 0.0, 0.0), | ||
rotation: (0.0, 0.0, 0.0, 1.0), | ||
scale: (1.0, 1.0, 1.0), | ||
)), | ||
(bevy_render::color::Color, (r: 0.8, g: 0.2, b: 0.2, a: 1.0)), | ||
], | ||
), | ||
( | ||
components: [ | ||
(bevy_transform::components::Transform, ( | ||
translation: (0.0, 2.0, 0.0), | ||
rotation: (0.0, 0.0, 0.0, 1.0), | ||
scale: (1.0, 1.0, 1.0), | ||
)), | ||
(bevy_render::color::Color, (r: 0.2, g: 0.8, b: 0.2, a: 1.0)), | ||
], | ||
), | ||
], | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
use bevy::prelude::*; | ||
use bevy_editor_core::SelectedEntity; | ||
|
||
pub struct OutlineGizmoPlugin; | ||
impl Plugin for OutlineGizmoPlugin { | ||
fn build(&self, app: &mut App) { | ||
app.init_resource::<ShowOutlines>() | ||
.add_systems(Startup, spawn_gizmo_toggle_ui) | ||
.add_systems(Update, outline_gizmo_system) | ||
.add_systems(Update, update_gizmo_toggle_text); | ||
} | ||
} | ||
|
||
#[derive(Resource, Default)] | ||
pub struct ShowOutlines(pub bool); | ||
|
||
// Marker for the toggle button text | ||
#[derive(Component)] | ||
struct GizmoToggleText; | ||
|
||
pub fn outline_gizmo_system( | ||
show: Res<ShowOutlines>, | ||
query: Query<&Transform>, | ||
selected_entity: Res<SelectedEntity>, | ||
mut gizmos: Gizmos, | ||
) { | ||
if !show.0 { | ||
return; | ||
} | ||
if let Some(entity) = selected_entity.0 { | ||
if let Ok(transform) = query.get(entity) { | ||
gizmos.cuboid(*transform, Color::srgb(1.0, 0.0, 0.0)); | ||
} | ||
} | ||
} | ||
|
||
pub fn spawn_gizmo_toggle_ui(mut commands: Commands) { | ||
info!("Spawning Gizmo Toggle UI"); | ||
commands | ||
.spawn(( | ||
Node { | ||
position_type: PositionType::Absolute, | ||
top: Val::Px(20.0), | ||
right: Val::Px(20.0), | ||
width: Val::Px(100.0), | ||
height: Val::Px(15.0), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The height of this button is smaller than the text inside which is not very pleasing to look at. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, i've fixed thisi by making the font smaller for now There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
align_items: AlignItems::Center, | ||
justify_content: JustifyContent::Center, | ||
..default() | ||
}, | ||
BackgroundColor(Color::srgb(0.2, 0.2, 0.2)), | ||
)) | ||
.with_children(|parent| { | ||
parent.spawn(( | ||
Text::new("Show Outlines"), | ||
TextFont::from_font_size(10.0), | ||
GizmoToggleText, | ||
)); | ||
}) | ||
.observe( | ||
|_trigger: Trigger<Pointer<Click>>, mut show_outlines: ResMut<ShowOutlines>| { | ||
show_outlines.0 = !show_outlines.0; | ||
}, | ||
); | ||
} | ||
|
||
// System to update the button text when ShowOutlines changes | ||
fn update_gizmo_toggle_text( | ||
show_outlines: Res<ShowOutlines>, | ||
mut query: Query<&mut Text, With<GizmoToggleText>>, | ||
) { | ||
if show_outlines.is_changed() { | ||
for mut text in &mut query { | ||
text.0 = if show_outlines.0 { | ||
"Hide Outlines".into() | ||
} else { | ||
"Show Outlines".into() | ||
}; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
( | ||
entities: [ | ||
( | ||
components: [ | ||
(bevy_transform::components::Transform, ( | ||
translation: (1.0, 0.0, 0.0), | ||
rotation: (0.0, 0.0, 0.0, 1.0), | ||
scale: (1.0, 1.0, 1.0), | ||
)), | ||
(bevy_render::color::Color, (r: 0.8, g: 0.2, b: 0.2, a: 1.0)), | ||
], | ||
), | ||
( | ||
components: [ | ||
(bevy_transform::components::Transform, ( | ||
translation: (0.0, 2.0, 0.0), | ||
rotation: (0.0, 0.0, 0.0, 1.0), | ||
scale: (1.0, 1.0, 1.0), | ||
)), | ||
(bevy_render::color::Color, (r: 0.2, g: 0.8, b: 0.2, a: 1.0)), | ||
], | ||
), | ||
], | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be only a temporary solution, it would be better to have a menu to manage which gizmo types are visible just like other game engines.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i agree with this - but beyond the scope of this PR. I just wanted to add something quick and dirty to show that we can add the outlines