Skip to content

Commit 57e94a3

Browse files
committed
Added and rewrote some comments.
1 parent 0528a33 commit 57e94a3

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

examples/picking.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use bevy::prelude::*;
22
use bevy_mod_outline::*;
33

4+
/// Tag to track if an object is selected or not
45
#[derive(Component)]
56
struct Selected;
67

@@ -97,8 +98,7 @@ fn on_click(
9798
// Disable propagation to prevent observers other than the first in the queue from responding
9899
event.propagate(false);
99100

100-
/// Remove every existing selection from every entity
101-
/// useful for when the user wants to deselect everything
101+
/// Helper function to deselect every selected entity
102102
fn deselect_all(
103103
commands: &mut Commands,
104104
query: &mut Query<(Entity, &mut OutlineVolume, Option<&Selected>)>,
@@ -113,16 +113,18 @@ fn on_click(
113113
}
114114
}
115115

116+
// Check if the user wants to select multiple objects
116117
let multi_select = keys.pressed(KeyCode::ShiftLeft) || keys.pressed(KeyCode::ShiftRight);
117118

118-
// Deselect everything if this is not a multi_select
119+
// Deselect everything if the user does not want to select multiple objects
119120
if !multi_select {
120121
deselect_all(&mut commands, &mut query);
121122
}
122123

123-
// Act on the target mesh
124+
// Select a mesh
124125
if let Ok((entity, mut outline, selected)) = query.get_mut(event.target) {
125126
if let Ok(mut entity) = commands.get_entity(entity) {
127+
// When selecting multiple objects, allow clicking a selected object to deselect it.
126128
if multi_select && selected.is_some() {
127129
entity.remove::<Selected>();
128130
outline.visible = false;

0 commit comments

Comments
 (0)