File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11use bevy:: prelude:: * ;
22use bevy_mod_outline:: * ;
33
4+ /// Tag to track if an object is selected or not
45#[ derive( Component ) ]
56struct 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 ;
You can’t perform that action at this time.
0 commit comments