Add read-only access to PointerInteraction (#15964)

# Objective
Re-add missing read-only access to `PointerInteraction`. This was missed
when bevy_mod_picking was upstreamed.
See
[here](https://docs.rs/bevy_mod_picking/latest/bevy_mod_picking/pointer/struct.PointerInteraction.html).
This commit is contained in:
Tim 2024-10-16 21:21:19 +00:00 committed by GitHub
parent 7482a0d26d
commit f4d9c52c0d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -17,7 +17,7 @@ use bevy_window::PrimaryWindow;
use uuid::Uuid; use uuid::Uuid;
use core::fmt::Debug; use core::{fmt::Debug, ops::Deref};
use crate::backend::HitData; use crate::backend::HitData;
@ -71,6 +71,21 @@ pub struct PointerInteraction {
pub(crate) sorted_entities: Vec<(Entity, HitData)>, pub(crate) sorted_entities: Vec<(Entity, HitData)>,
} }
impl PointerInteraction {
/// Returns the nearest hit entity and data about that intersection.
pub fn get_nearest_hit(&self) -> Option<&(Entity, HitData)> {
self.sorted_entities.first()
}
}
impl Deref for PointerInteraction {
type Target = Vec<(Entity, HitData)>;
fn deref(&self) -> &Self::Target {
&self.sorted_entities
}
}
/// A resource that maps each [`PointerId`] to their [`Entity`] for easy lookups. /// A resource that maps each [`PointerId`] to their [`Entity`] for easy lookups.
#[derive(Debug, Clone, Default, Resource)] #[derive(Debug, Clone, Default, Resource)]
pub struct PointerMap { pub struct PointerMap {