mirror of
https://github.com/bevyengine/bevy
synced 2024-11-10 15:14:50 +00:00
Get Change Tick methods for Resources (#11404)
# Objective - Add methods to get Change Ticks for a given resource by type or ComponentId - Fixes #11390 The `is_resource_id_changed` requested in the Issue already exists, this adds their request for `get_resource_change_ticks` ## Solution - Added two methods to get change ticks by Type or ComponentId
This commit is contained in:
parent
c62ad4b2c4
commit
d151883f3e
1 changed files with 24 additions and 1 deletions
|
@ -18,7 +18,10 @@ use crate::{
|
|||
archetype::{ArchetypeComponentId, ArchetypeId, ArchetypeRow, Archetypes},
|
||||
bundle::{Bundle, BundleInserter, BundleSpawner, Bundles},
|
||||
change_detection::{MutUntyped, TicksMut},
|
||||
component::{Component, ComponentDescriptor, ComponentId, ComponentInfo, Components, Tick},
|
||||
component::{
|
||||
Component, ComponentDescriptor, ComponentId, ComponentInfo, ComponentTicks, Components,
|
||||
Tick,
|
||||
},
|
||||
entity::{AllocAtWithoutReplacement, Entities, Entity, EntityLocation},
|
||||
event::{Event, EventId, Events, SendBatchIds},
|
||||
query::{DebugCheckedUnwrap, QueryData, QueryEntityError, QueryFilter, QueryState},
|
||||
|
@ -1255,6 +1258,26 @@ impl World {
|
|||
.unwrap_or(false)
|
||||
}
|
||||
|
||||
/// Retrieves the change ticks for the given resource.
|
||||
pub fn get_resource_change_ticks<R: Resource>(&self) -> Option<ComponentTicks> {
|
||||
self.components
|
||||
.get_resource_id(TypeId::of::<R>())
|
||||
.and_then(|component_id| self.get_resource_change_ticks_by_id(component_id))
|
||||
}
|
||||
|
||||
/// Retrieves the change ticks for the given [`ComponentId`].
|
||||
///
|
||||
/// **You should prefer to use the typed API [`World::get_resource_change_ticks`] where possible.**
|
||||
pub fn get_resource_change_ticks_by_id(
|
||||
&self,
|
||||
component_id: ComponentId,
|
||||
) -> Option<ComponentTicks> {
|
||||
self.storages
|
||||
.resources
|
||||
.get(component_id)
|
||||
.and_then(|resource| resource.get_ticks())
|
||||
}
|
||||
|
||||
/// Gets a reference to the resource of the given type
|
||||
///
|
||||
/// # Panics
|
||||
|
|
Loading…
Reference in a new issue