Struct amethyst_assets::Prefab [−][src]
pub struct Prefab<T> { /* fields omitted */ }
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
Methods
impl<T> Prefab<T>
[src]
impl<T> Prefab<T>
pub fn new() -> Self
[src]
pub fn new() -> Self
Create new empty prefab
pub fn new_main(data: T) -> Self
[src]
pub fn new_main(data: T) -> Self
Create a prefab with data for only the main Entity
pub fn main(&mut self, data: Option<T>)
[src]
pub fn main(&mut self, data: Option<T>)
Set main Entity
data
pub fn add(&mut self, parent: Option<usize>, data: Option<T>) -> usize
[src]
pub fn add(&mut self, parent: Option<usize>, data: Option<T>) -> usize
Add a new entity to the prefab, with optional data and parent.
pub fn len(&self) -> usize
[src]
pub fn len(&self) -> usize
Number of entities in the prefab, including the main entity
pub fn new_entity(&mut self) -> usize
[src]
pub fn new_entity(&mut self) -> usize
Create a new entity in the prefab, with no data and no parent
pub fn entity(&mut self, index: usize) -> Option<&mut PrefabEntity<T>>
[src]
pub fn entity(&mut self, index: usize) -> Option<&mut PrefabEntity<T>>
Get mutable access to the PrefabEntity
with the given index
pub fn entities<'a>(
&'a self
) -> impl Iterator<Item = &'a PrefabEntity<T>>
[src]
pub fn entities<'a>(
&'a self
) -> impl Iterator<Item = &'a PrefabEntity<T>>
Get immutable access to all entities in the prefab
ⓘImportant traits for &'a mut Rpub fn data_or_default(&mut self, index: usize) -> &mut T where
T: Default,
[src]
pub fn data_or_default(&mut self, index: usize) -> &mut T where
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
pub fn loading(&self) -> bool
[src]
pub fn loading(&self) -> bool
Check if sub asset loading have been triggered
pub fn progress(&self) -> &ProgressCounter
[src]
pub fn progress(&self) -> &ProgressCounter
Get the ProgressCounter
for the sub asset loading.
Panics
If sub asset loading have not been triggered
pub fn trigger_sub_loading<'a>(
&mut self,
system_data: &mut <T as PrefabData<'a>>::SystemData
) -> Result<bool, PrefabError> where
T: PrefabData<'a>,
[src]
pub fn trigger_sub_loading<'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
impl<T: Default> Default for Prefab<T>
[src]
impl<T: Default> Default for Prefab<T>
impl<T> Asset for Prefab<T> where
T: Send + Sync + 'static,
[src]
impl<T> Asset for Prefab<T> where
T: Send + Sync + 'static,
const NAME: &'static str
NAME: &'static str = "PREFAB"
An identifier for this asset used for debugging.
type Data = Self
The Data
type the asset can be created from.
type HandleStorage = FlaggedStorage<Handle<Self>, DenseVecStorage<Handle<Self>>>
The ECS storage type to be used. You'll want to use VecStorage
in most cases.