Make sprite picking opt-in (#17842)
# Objective Fix https://github.com/bevyengine/bevy/issues/17108 See https://github.com/bevyengine/bevy/issues/17108#issuecomment-2653020889 ## Solution - Make the query match `&Pickable` instead `Option<&Pickable>` ## Testing - Run the `sprite_picking` example and everything still work ## Migration Guide - Sprite picking are now opt-in, make sure you insert `Pickable` component when using sprite picking. ```diff -commands.spawn(Sprite { .. } ); +commands.spawn((Sprite { .. }, Pickable::default()); ```
This commit is contained in:
parent
cb628516d1
commit
f7b2a02224
@ -42,7 +42,7 @@ pub enum SpritePickingMode {
|
||||
#[reflect(Resource, Default)]
|
||||
pub struct SpritePickingSettings {
|
||||
/// When set to `true` sprite picking will only consider cameras marked with
|
||||
/// [`SpritePickingCamera`] and entities marked with [`Pickable`]. `false` by default.
|
||||
/// [`SpritePickingCamera`].
|
||||
///
|
||||
/// This setting is provided to give you fine-grained control over which cameras and entities
|
||||
/// should be used by the sprite picking backend at runtime.
|
||||
@ -94,7 +94,7 @@ fn sprite_picking(
|
||||
Entity,
|
||||
&Sprite,
|
||||
&GlobalTransform,
|
||||
Option<&Pickable>,
|
||||
&Pickable,
|
||||
&ViewVisibility,
|
||||
)>,
|
||||
mut output: EventWriter<PointerHits>,
|
||||
@ -102,8 +102,7 @@ fn sprite_picking(
|
||||
let mut sorted_sprites: Vec<_> = sprite_query
|
||||
.iter()
|
||||
.filter_map(|(entity, sprite, transform, pickable, vis)| {
|
||||
let marker_requirement = !settings.require_markers || pickable.is_some();
|
||||
if !transform.affine().is_nan() && vis.get() && marker_requirement {
|
||||
if !transform.affine().is_nan() && vis.get() {
|
||||
Some((entity, sprite, transform, pickable))
|
||||
} else {
|
||||
None
|
||||
@ -219,8 +218,7 @@ fn sprite_picking(
|
||||
}
|
||||
};
|
||||
|
||||
blocked = cursor_in_valid_pixels_of_sprite
|
||||
&& pickable.is_none_or(|p| p.should_block_lower);
|
||||
blocked = cursor_in_valid_pixels_of_sprite && pickable.should_block_lower;
|
||||
|
||||
cursor_in_valid_pixels_of_sprite.then(|| {
|
||||
let hit_pos_world =
|
||||
|
@ -60,6 +60,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
|
||||
.spawn((
|
||||
Sprite::from_color(Color::BLACK, sprite_size),
|
||||
Transform::from_xyz(i * len - len, j * len - len, -1.0),
|
||||
Pickable::default(),
|
||||
))
|
||||
.observe(recolor_on::<Pointer<Over>>(Color::srgb(0.0, 1.0, 1.0)))
|
||||
.observe(recolor_on::<Pointer<Out>>(Color::BLACK))
|
||||
@ -79,6 +80,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
|
||||
Transform::from_xyz(i * len - len, j * len - len, 0.0)
|
||||
.with_scale(Vec3::splat(1.0 + (i - 1.0) * 0.2))
|
||||
.with_rotation(Quat::from_rotation_z((j - 1.0) * 0.2)),
|
||||
Pickable::default(),
|
||||
))
|
||||
.observe(recolor_on::<Pointer<Over>>(Color::srgb(0.0, 1.0, 0.0)))
|
||||
.observe(recolor_on::<Pointer<Out>>(Color::srgb(1.0, 0.0, 0.0)))
|
||||
@ -140,6 +142,7 @@ fn setup_atlas(
|
||||
Transform::from_xyz(300.0, 0.0, 0.0).with_scale(Vec3::splat(6.0)),
|
||||
animation_indices,
|
||||
AnimationTimer(Timer::from_seconds(0.1, TimerMode::Repeating)),
|
||||
Pickable::default(),
|
||||
))
|
||||
.observe(recolor_on::<Pointer<Over>>(Color::srgb(0.0, 1.0, 1.0)))
|
||||
.observe(recolor_on::<Pointer<Out>>(Color::srgb(1.0, 1.0, 1.0)))
|
||||
|
Loading…
Reference in New Issue
Block a user