@@ -293,20 +293,31 @@ pub struct DefaultPickingPlugins;
293
293
impl PluginGroup for DefaultPickingPlugins {
294
294
fn build ( self ) -> PluginGroupBuilder {
295
295
PluginGroupBuilder :: start :: < Self > ( )
296
- . add ( input:: PointerInputPlugin :: default ( ) )
297
- . add ( PickingPlugin :: default ( ) )
296
+ . add ( input:: PointerInputPlugin )
297
+ . add ( PickingPlugin )
298
298
. add ( InteractionPlugin )
299
299
}
300
300
}
301
301
302
- /// This plugin sets up the core picking infrastructure. It receives input events, and provides the shared
303
- /// types used by other picking plugins.
304
- ///
305
- /// This plugin contains several settings, and is added to the world as a resource after initialization. You
306
- /// can configure picking settings at runtime through the resource.
307
302
#[ derive( Copy , Clone , Debug , Resource , Reflect ) ]
308
303
#[ reflect( Resource , Default , Debug , Clone ) ]
309
- pub struct PickingPlugin {
304
+ /// Controls the behavior of picking
305
+ ///
306
+ /// ## Custom initialization
307
+ /// ```
308
+ /// # use bevy_app::App;
309
+ /// # use bevy_picking::{PickingSettings, PickingPlugin};
310
+ /// App::new()
311
+ /// .insert_resource(PickingSettings {
312
+ /// is_enabled: true,
313
+ /// is_input_enabled: false,
314
+ /// is_hover_enabled: true,
315
+ /// is_window_picking_enabled: false,
316
+ /// })
317
+ /// // or DefaultPlugins
318
+ /// .add_plugins(PickingPlugin);
319
+ /// ```
320
+ pub struct PickingSettings {
310
321
/// Enables and disables all picking features.
311
322
pub is_enabled : bool ,
312
323
/// Enables and disables input collection.
@@ -317,7 +328,7 @@ pub struct PickingPlugin {
317
328
pub is_window_picking_enabled : bool ,
318
329
}
319
330
320
- impl PickingPlugin {
331
+ impl PickingSettings {
321
332
/// Whether or not input collection systems should be running.
322
333
pub fn input_should_run ( state : Res < Self > ) -> bool {
323
334
state. is_input_enabled && state. is_enabled
@@ -335,7 +346,7 @@ impl PickingPlugin {
335
346
}
336
347
}
337
348
338
- impl Default for PickingPlugin {
349
+ impl Default for PickingSettings {
339
350
fn default ( ) -> Self {
340
351
Self {
341
352
is_enabled : true ,
@@ -346,9 +357,18 @@ impl Default for PickingPlugin {
346
357
}
347
358
}
348
359
360
+ /// This plugin sets up the core picking infrastructure. It receives input events, and provides the shared
361
+ /// types used by other picking plugins.
362
+ ///
363
+ /// Behavior of picking can be controlled by modifying [`PickingSettings`].
364
+ ///
365
+ /// [`PickingSettings`] will be initialized with default values if it
366
+ /// is not present at the moment this is added to the app.
367
+ pub struct PickingPlugin ;
368
+
349
369
impl Plugin for PickingPlugin {
350
370
fn build ( & self , app : & mut App ) {
351
- app. insert_resource ( * self )
371
+ app. init_resource :: < PickingSettings > ( )
352
372
. init_resource :: < pointer:: PointerMap > ( )
353
373
. init_resource :: < backend:: ray:: RayMap > ( )
354
374
. add_event :: < pointer:: PointerInput > ( )
@@ -369,7 +389,7 @@ impl Plugin for PickingPlugin {
369
389
. add_systems (
370
390
PreUpdate ,
371
391
window:: update_window_hits
372
- . run_if ( Self :: window_picking_should_run)
392
+ . run_if ( PickingSettings :: window_picking_should_run)
373
393
. in_set ( PickingSystems :: Backend ) ,
374
394
)
375
395
. configure_sets (
@@ -382,15 +402,15 @@ impl Plugin for PickingPlugin {
382
402
. configure_sets (
383
403
PreUpdate ,
384
404
(
385
- PickingSystems :: ProcessInput . run_if ( Self :: input_should_run) ,
405
+ PickingSystems :: ProcessInput . run_if ( PickingSettings :: input_should_run) ,
386
406
PickingSystems :: Backend ,
387
- PickingSystems :: Hover . run_if ( Self :: hover_should_run) ,
407
+ PickingSystems :: Hover . run_if ( PickingSettings :: hover_should_run) ,
388
408
PickingSystems :: PostHover ,
389
409
PickingSystems :: Last ,
390
410
)
391
411
. chain ( ) ,
392
412
)
393
- . register_type :: < Self > ( )
413
+ . register_type :: < PickingSettings > ( )
394
414
. register_type :: < Pickable > ( )
395
415
. register_type :: < hover:: PickingInteraction > ( )
396
416
. register_type :: < hover:: Hovered > ( )
0 commit comments