Struct amethyst_assets::Prefab
source · pub struct Prefab<T> { /* private fields */ }
Expand description
Main Prefab
structure, containing all data loaded in a single prefab.
Contains a list prefab data for the entities affected by the prefab. The first entry in the
entities
list will be applied to the main Entity
the Handle
is placed on, and all other
entries will trigger creation of a new entity. Note that the parent index is ignored for the
first entry in the list.
The recommended way of loading resources is to place them on the main Entity
.
Example:
If the prefab contains 3 new entities A
, B
and C
, and the main Entity
that the Handle
is placed on is E
, and we want the graph to be A -> E
, B -> E
, C -> B
(parent links),
the data will be as follows:
Prefab {
entities: vec![
PrefabEntity { parent: None /* not used */, .. },
PrefabEntity { parent: Some(0), .. },
PrefabEntity { parent: Some(0), .. },
PrefabEntity { parent: Some(2), .. },
],
}
Type parameters:
T
:PrefabData
Implementations
sourceimpl<T> Prefab<T>
impl<T> Prefab<T>
sourcepub fn add(&mut self, parent: Option<usize>, data: Option<T>) -> usize
pub fn add(&mut self, parent: Option<usize>, data: Option<T>) -> usize
Add a new entity to the prefab, with optional data and parent.
sourcepub fn new_entity(&mut self) -> usize
pub fn new_entity(&mut self) -> usize
Create a new entity in the prefab, with no data and no parent
sourcepub fn entity(&mut self, index: usize) -> Option<&mut PrefabEntity<T>>
pub fn entity(&mut self, index: usize) -> Option<&mut PrefabEntity<T>>
Get mutable access to the PrefabEntity
with the given index
sourcepub fn entities(&self) -> impl Iterator<Item = &PrefabEntity<T>>
pub fn entities(&self) -> impl Iterator<Item = &PrefabEntity<T>>
Get immutable access to all entities in the prefab
sourcepub fn data_or_default(&mut self, index: usize) -> &mut Twhere
T: Default,
pub fn data_or_default(&mut self, index: usize) -> &mut Twhere
T: Default,
Get mutable access to the data in the PrefabEntity
with the given index
If data is None, this will insert a default value for T
Panics
If the given index do not have a PrefabEntity
sourcepub fn progress(&self) -> &ProgressCounter
pub fn progress(&self) -> &ProgressCounter
Get the ProgressCounter
for the sub asset loading.
Panics
If sub asset loading has not been triggered.
sourcepub fn load_sub_assets<'a>(
&mut self,
system_data: &mut <T as PrefabData<'a>>::SystemData
) -> Result<bool, PrefabError>where
T: PrefabData<'a>,
pub fn load_sub_assets<'a>(
&mut self,
system_data: &mut <T as PrefabData<'a>>::SystemData
) -> Result<bool, PrefabError>where
T: PrefabData<'a>,
Trigger sub asset loading for the asset
Trait Implementations
sourceimpl<T> Asset for Prefab<T>where
T: Send + Sync + 'static,
impl<T> Asset for Prefab<T>where
T: Send + Sync + 'static,
type HandleStorage = FlaggedStorage<Handle<Prefab<T>>, DenseVecStorage<Handle<Prefab<T>>>>
type HandleStorage = FlaggedStorage<Handle<Prefab<T>>, DenseVecStorage<Handle<Prefab<T>>>>
VecStorage
in most cases.sourceimpl<'de, T> Deserialize<'de> for Prefab<T>where
T: Deserialize<'de>,
impl<'de, T> Deserialize<'de> for Prefab<T>where
T: Deserialize<'de>,
sourcefn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations
impl<T> !RefUnwindSafe for Prefab<T>
impl<T> Send for Prefab<T>where
T: Send,
impl<T> Sync for Prefab<T>where
T: Sync,
impl<T> Unpin for Prefab<T>where
T: Unpin,
impl<T> !UnwindSafe for Prefab<T>
Blanket Implementations
impl<T> Any for Twhere
T: Any,
impl<T> Any for Twhere
T: Any,
fn get_type_id(&self) -> TypeId
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<T> Pointable for T
impl<T> Pointable for T
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self
from the equivalent element of its
superset. Read morefn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self
is actually part of its subset T
(and can be converted to it).unsafe fn to_subset_unchecked(&self) -> SS
unsafe fn to_subset_unchecked(&self) -> SS
self.to_subset
but without any property checks. Always succeeds.fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self
to the equivalent element of its superset.impl<T> TryDefault for Twhere
T: Default,
impl<T> TryDefault for Twhere
T: Default,
fn try_default() -> Result<T, String>
fn try_default() -> Result<T, String>
fn unwrap_default() -> Self
fn unwrap_default() -> Self
try_default
and panics on an error case.