mirror of
https://github.com/bevyengine/bevy
synced 2024-11-22 04:33:37 +00:00
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:
parent
7482a0d26d
commit
f4d9c52c0d
1 changed files with 16 additions and 1 deletions
|
@ -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 {
|
||||||
|
|
Loading…
Reference in a new issue