[−][src]Struct amethyst_assets::Prefab
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 we want to give the existing Baker entity a Knife and a Plate with a
Cake on it. The prefab contains 3 new entities Knife
, Plate
,
and Cake
, and the main Entity
that the Handle
is placed on is the
Baker
. We want the graph to be Knife on Baker
, Plate on Baker
,
Cake on Plate
using parent links. The data will be as follows:
Prefab { entities: vec![ PrefabEntity { parent: None, .. }, /* #0 Baker, parent is not used */ PrefabEntity { parent: Some(0), .. }, /* #1 Knife parented to Baker #0 */ PrefabEntity { parent: Some(0), .. }, /* #2 Plate parented to Baker #0 */ PrefabEntity { parent: Some(2), .. }, /* #3 Cake parented to Plate #2 */ ], }
Type parameters:
T
:PrefabData
Methods
impl<T> Prefab<T>
[src]
pub fn new() -> Self
[src]
Create new empty prefab
pub fn new_main(data: T) -> Self
[src]
Create a prefab with data for only the main Entity
pub fn main(&mut self, data: Option<T>)
[src]
Set main Entity
data
pub fn add(&mut self, parent: Option<usize>, data: Option<T>) -> usize
[src]
Add a new entity to the prefab, with optional data and parent.
pub fn len(&self) -> usize
[src]
Number of entities in the prefab, including the main entity
pub fn is_empty(&self) -> bool
[src]
Returns true
if the prefab contains no entities.
pub fn new_entity(&mut self) -> usize
[src]
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]
Get mutable access to the PrefabEntity
with the given index
pub fn entities(&self) -> impl Iterator<Item = &PrefabEntity<T>>
[src]
Get immutable access to all entities in the prefab
pub fn data_or_default(&mut self, index: usize) -> &mut T where
T: Default,
[src]
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 data_or_insert_with(
&mut self,
index: usize,
func: impl FnOnce() -> T
) -> &mut T
[src]
&mut self,
index: usize,
func: impl FnOnce() -> T
) -> &mut T
Get mutable access to the data in the PrefabEntity
with the given index
If data is None, this will insert a value for T
computed with a closure
Panics
If the given index do not have a PrefabEntity
pub fn loading(&self) -> bool
[src]
Check if sub asset loading have been triggered
pub fn progress(&self) -> &ProgressCounter
[src]
Get the ProgressCounter
for the sub asset loading.
Panics
If sub asset loading has not been triggered.
pub fn load_sub_assets<'a>(
&mut self,
system_data: &mut <T as PrefabData<'a>>::SystemData
) -> Result<bool, Error> where
T: PrefabData<'a>,
[src]
&mut self,
system_data: &mut <T as PrefabData<'a>>::SystemData
) -> Result<bool, Error> where
T: PrefabData<'a>,
Trigger sub asset loading for the asset
Trait Implementations
impl<T> Asset for Prefab<T> where
T: Send + Sync + 'static,
[src]
T: Send + Sync + 'static,
const NAME: &'static str
[src]
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 DenseVecStorage
in most cases.
impl<T: Default> Default for Prefab<T>
[src]
impl<T> Serialize for Prefab<T> where
T: Serialize,
[src]
T: Serialize,
fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error> where
__S: Serializer,
[src]
__S: Serializer,
impl<'de, T> Deserialize<'de> for Prefab<T> where
T: Deserialize<'de>,
[src]
T: Deserialize<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
[src]
__D: Deserializer<'de>,
Auto Trait Implementations
impl<T> Unpin for Prefab<T> where
T: Unpin,
T: Unpin,
impl<T> Sync for Prefab<T> where
T: Sync,
T: Sync,
impl<T> Send for Prefab<T> where
T: Send,
T: Send,
impl<T> !UnwindSafe for Prefab<T>
impl<T> !RefUnwindSafe for Prefab<T>
Blanket Implementations
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Same<T> for T
[src]
type Output = T
Should always be Self
impl<SS, SP> SupersetOf<SS> for SP where
SS: SubsetOf<SP>,
[src]
SS: SubsetOf<SP>,
fn to_subset(&self) -> Option<SS>
[src]
fn is_in_subset(&self) -> bool
[src]
unsafe fn to_subset_unchecked(&self) -> SS
[src]
fn from_subset(element: &SS) -> SP
[src]
impl<T> DeserializeOwned for T where
T: Deserialize<'de>,
[src]
T: Deserialize<'de>,
impl<T> Resource for T where
T: Any + Send + Sync,
[src]
T: Any + Send + Sync,
impl<T> Any for T where
T: Any,
[src]
T: Any,
fn get_type_id(&self) -> TypeId
[src]
impl<T> TryDefault for T where
T: Default,
[src]
T: Default,
fn try_default() -> Result<T, String>
[src]
fn unwrap_default() -> Self
[src]
Calls try_default
and panics on an error case.
impl<T> Event for T where
T: Send + Sync + 'static,
[src]
T: Send + Sync + 'static,
impl<T> Erased for T
[src]
impl<T> Serialize for T where
T: Serialize + ?Sized,
[src]
T: Serialize + ?Sized,