mirror of
https://github.com/bevyengine/bevy
synced 2024-11-10 15:14:50 +00:00
Handle::from_untyped
This commit is contained in:
parent
ed9eb88835
commit
2d0bff97a8
2 changed files with 21 additions and 6 deletions
|
@ -22,6 +22,14 @@ impl<T> Handle<T> {
|
|||
marker: PhantomData,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn from_untyped(untyped_handle: HandleUntyped) -> Option<Handle<T>> where T: 'static {
|
||||
if TypeId::of::<T>() == untyped_handle.type_id {
|
||||
Some(Handle::new(untyped_handle.id))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Hash for Handle<T> {
|
||||
|
@ -88,11 +96,7 @@ where
|
|||
T: 'static,
|
||||
{
|
||||
fn from(handle: HandleUntyped) -> Self {
|
||||
if TypeId::of::<T>() != handle.type_id {
|
||||
panic!("attempted to convert untyped handle to incorrect typed handle");
|
||||
}
|
||||
|
||||
Handle::new(handle.id)
|
||||
Handle::from_untyped(handle).expect("attempted to convert untyped handle to incorrect typed handle")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
use crate::{asset::HandleUntyped, render::render_resource::RenderResourceAssignments};
|
||||
use crate::{
|
||||
asset::{Handle, HandleUntyped},
|
||||
render::render_resource::RenderResourceAssignments,
|
||||
};
|
||||
use legion::prelude::Entity;
|
||||
use std::collections::{HashMap, HashSet};
|
||||
|
||||
|
@ -23,4 +26,12 @@ impl Batch {
|
|||
self.current_instanced_entity_index += 1;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_handle<T>(&self) -> Option<Handle<T>> where T: 'static {
|
||||
self.handles
|
||||
.iter()
|
||||
.map(|h| Handle::from_untyped(*h))
|
||||
.find(|h| h.is_some())
|
||||
.map(|h| h.unwrap())
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue