@@ -13,12 +13,10 @@ pub use crate::{
13
13
} ;
14
14
pub use bevy_mod_raycast:: { Primitive3d , RaycastMesh , RaycastSource } ;
15
15
16
- use bevy:: {
17
- app:: PluginGroupBuilder , asset:: Asset , ecs:: schedule:: ShouldRun , prelude:: * , ui:: FocusPolicy ,
18
- } ;
16
+ use bevy:: { app:: PluginGroupBuilder , asset:: Asset , prelude:: * , ui:: FocusPolicy } ;
19
17
use highlight:: { get_initial_mesh_highlight_asset, Highlight } ;
20
18
21
- #[ derive( Debug , Hash , PartialEq , Eq , Clone , SystemLabel ) ]
19
+ #[ derive( Debug , Hash , PartialEq , Eq , Clone , SystemSet ) ]
22
20
pub enum PickingSystem {
23
21
UpdatePickSourcePositions ,
24
22
BuildRays ,
@@ -29,6 +27,9 @@ pub enum PickingSystem {
29
27
PauseForBlockers ,
30
28
Focus ,
31
29
Events ,
30
+ PickingSet ,
31
+ InteractableSet ,
32
+ CustomHighlightSet ,
32
33
}
33
34
34
35
/// A type alias for the concrete [RaycastMesh](bevy_mod_raycast::RaycastMesh) type used for Picking.
@@ -41,6 +42,7 @@ pub type PickingCamera = RaycastSource<PickingRaycastSet>;
41
42
/// meshes or ray sources that are being used by the picking plugin can be used by other ray
42
43
/// casting systems because they will have distinct types, e.g.: `RaycastMesh<PickingRaycastSet>`
43
44
/// vs. `RaycastMesh<MySuperCoolRaycastingType>`, and as such wil not result in collisions.
45
+ #[ derive( Clone , Reflect ) ]
44
46
pub struct PickingRaycastSet ;
45
47
46
48
#[ derive( Clone , Debug , Resource ) ]
@@ -60,14 +62,6 @@ impl Default for PickingPluginsState {
60
62
}
61
63
}
62
64
63
- fn simple_criteria ( flag : bool ) -> ShouldRun {
64
- if flag {
65
- ShouldRun :: Yes
66
- } else {
67
- ShouldRun :: No
68
- }
69
- }
70
-
71
65
#[ derive( Default , Resource ) ]
72
66
pub struct PausedForBlockers ( pub ( crate ) bool ) ;
73
67
impl PausedForBlockers {
@@ -115,31 +109,23 @@ pub struct PickingPlugin;
115
109
impl Plugin for PickingPlugin {
116
110
fn build ( & self , app : & mut App ) {
117
111
app. init_resource :: < PickingPluginsState > ( )
118
- . add_system_set_to_stage (
119
- CoreStage :: PreUpdate ,
120
- SystemSet :: new ( )
121
- . with_run_criteria ( |state : Res < PickingPluginsState > | {
122
- simple_criteria ( state. enable_picking )
123
- } )
124
- . with_system (
125
- update_pick_source_positions
126
- . label ( PickingSystem :: UpdatePickSourcePositions )
127
- . before ( PickingSystem :: BuildRays ) ,
128
- )
129
- . with_system (
130
- bevy_mod_raycast:: build_rays :: < PickingRaycastSet >
131
- . label ( PickingSystem :: BuildRays )
132
- . before ( PickingSystem :: UpdateRaycast ) ,
133
- )
134
- . with_system (
135
- bevy_mod_raycast:: update_raycast :: < PickingRaycastSet >
136
- . label ( PickingSystem :: UpdateRaycast )
137
- . before ( PickingSystem :: UpdateIntersections ) ,
138
- )
139
- . with_system (
140
- bevy_mod_raycast:: update_intersections :: < PickingRaycastSet >
141
- . label ( PickingSystem :: UpdateIntersections ) ,
142
- ) ,
112
+ . add_systems (
113
+ (
114
+ update_pick_source_positions. in_set ( PickingSystem :: UpdatePickSourcePositions ) ,
115
+ bevy_mod_raycast:: build_rays :: < PickingRaycastSet >
116
+ . in_set ( PickingSystem :: BuildRays ) ,
117
+ bevy_mod_raycast:: update_raycast :: < PickingRaycastSet >
118
+ . in_set ( PickingSystem :: UpdateRaycast ) ,
119
+ bevy_mod_raycast:: update_intersections :: < PickingRaycastSet >
120
+ . in_set ( PickingSystem :: UpdateIntersections ) ,
121
+ )
122
+ . chain ( )
123
+ . in_set ( PickingSystem :: PickingSet ) ,
124
+ )
125
+ . configure_set (
126
+ PickingSystem :: PickingSet
127
+ . run_if ( |state : Res < PickingPluginsState > | state. enable_picking )
128
+ . in_base_set ( CoreSet :: PreUpdate ) ,
143
129
) ;
144
130
}
145
131
}
@@ -149,32 +135,21 @@ impl Plugin for InteractablePickingPlugin {
149
135
fn build ( & self , app : & mut App ) {
150
136
app. init_resource :: < PausedForBlockers > ( )
151
137
. add_event :: < PickingEvent > ( )
152
- . add_system_set_to_stage (
153
- CoreStage :: PreUpdate ,
154
- SystemSet :: new ( )
155
- . with_run_criteria ( |state : Res < PickingPluginsState > | {
156
- simple_criteria ( state. enable_interacting )
157
- } )
158
- . with_system (
159
- pause_for_picking_blockers
160
- . label ( PickingSystem :: PauseForBlockers )
161
- . after ( PickingSystem :: UpdateIntersections ) ,
162
- )
163
- . with_system (
164
- mesh_focus
165
- . label ( PickingSystem :: Focus )
166
- . after ( PickingSystem :: PauseForBlockers ) ,
167
- )
168
- . with_system (
169
- mesh_selection
170
- . label ( PickingSystem :: Selection )
171
- . after ( PickingSystem :: Focus ) ,
172
- )
173
- . with_system (
174
- mesh_events_system
175
- . label ( PickingSystem :: Events )
176
- . after ( PickingSystem :: Selection ) ,
177
- ) ,
138
+ . add_systems (
139
+ (
140
+ pause_for_picking_blockers. in_set ( PickingSystem :: PauseForBlockers ) ,
141
+ mesh_focus. in_set ( PickingSystem :: Focus ) ,
142
+ mesh_selection. in_set ( PickingSystem :: Selection ) ,
143
+ mesh_events_system. in_set ( PickingSystem :: Events ) ,
144
+ )
145
+ . chain ( )
146
+ . in_set ( PickingSystem :: InteractableSet ) ,
147
+ )
148
+ . configure_set (
149
+ PickingSystem :: InteractableSet
150
+ . run_if ( |state : Res < PickingPluginsState > | state. enable_interacting )
151
+ . in_base_set ( CoreSet :: PreUpdate )
152
+ . after ( PickingSystem :: UpdateIntersections ) ,
178
153
) ;
179
154
}
180
155
}
@@ -194,32 +169,30 @@ where
194
169
app. add_startup_system ( move |mut commands : Commands , assets : ResMut < Assets < T > > | {
195
170
commands. insert_resource ( highlighting_default ( assets) ) ;
196
171
} )
197
- . add_system_set_to_stage (
198
- CoreStage :: PreUpdate ,
199
- SystemSet :: new ( )
200
- . with_run_criteria ( |state : Res < PickingPluginsState > | {
201
- simple_criteria ( state. enable_highlighting )
202
- } )
203
- . with_system (
204
- get_initial_mesh_highlight_asset :: < T >
205
- . after ( PickingSystem :: UpdateIntersections )
206
- . before ( PickingSystem :: Highlighting ) ,
207
- )
208
- . with_system (
209
- mesh_highlighting :: < T >
210
- . label ( PickingSystem :: Highlighting )
211
- . before ( PickingSystem :: Events ) ,
212
- ) ,
172
+ . add_systems (
173
+ (
174
+ get_initial_mesh_highlight_asset :: < T > ,
175
+ mesh_highlighting :: < T > . in_set ( PickingSystem :: Highlighting ) ,
176
+ )
177
+ . chain ( )
178
+ . in_set ( PickingSystem :: CustomHighlightSet ) ,
179
+ )
180
+ . configure_set (
181
+ PickingSystem :: CustomHighlightSet
182
+ . run_if ( |state : Res < PickingPluginsState > | state. enable_highlighting )
183
+ . in_base_set ( CoreSet :: PreUpdate )
184
+ . before ( PickingSystem :: Events )
185
+ . after ( PickingSystem :: UpdateIntersections ) ,
213
186
) ;
214
187
}
215
188
}
216
189
217
190
pub struct DebugCursorPickingPlugin ;
218
191
impl Plugin for DebugCursorPickingPlugin {
219
192
fn build ( & self , app : & mut App ) {
220
- app. add_system_to_stage (
221
- CoreStage :: PreUpdate ,
193
+ app. add_system (
222
194
bevy_mod_raycast:: update_debug_cursor :: < PickingRaycastSet >
195
+ . in_base_set ( CoreSet :: PreUpdate )
223
196
. after ( PickingSystem :: UpdateIntersections ) ,
224
197
) ;
225
198
}
@@ -228,9 +201,10 @@ impl Plugin for DebugCursorPickingPlugin {
228
201
pub struct DebugEventsPickingPlugin ;
229
202
impl Plugin for DebugEventsPickingPlugin {
230
203
fn build ( & self , app : & mut App ) {
231
- app. add_system_to_stage (
232
- CoreStage :: PreUpdate ,
233
- event_debug_system. after ( PickingSystem :: Events ) ,
204
+ app. add_system (
205
+ event_debug_system
206
+ . in_base_set ( CoreSet :: PreUpdate )
207
+ . after ( PickingSystem :: Events ) ,
234
208
) ;
235
209
}
236
210
}
@@ -250,7 +224,7 @@ impl Default for PickingCameraBundle {
250
224
}
251
225
}
252
226
253
- #[ derive( Bundle , Default ) ]
227
+ #[ derive( Bundle ) ]
254
228
pub struct PickableBundle {
255
229
pub pickable_mesh : PickableMesh ,
256
230
pub interaction : Interaction ,
@@ -259,3 +233,16 @@ pub struct PickableBundle {
259
233
pub selection : Selection ,
260
234
pub hover : Hover ,
261
235
}
236
+
237
+ impl Default for PickableBundle {
238
+ fn default ( ) -> Self {
239
+ Self {
240
+ pickable_mesh : default ( ) ,
241
+ interaction : default ( ) ,
242
+ focus_policy : FocusPolicy :: Block ,
243
+ highlight : default ( ) ,
244
+ selection : default ( ) ,
245
+ hover : default ( ) ,
246
+ }
247
+ }
248
+ }
0 commit comments