[][src]Struct amethyst_assets::Prefab

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 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:

This example is not tested
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:

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]

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]

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]

Trigger sub asset loading for the asset

Trait Implementations

impl<T> Asset for Prefab<T> where
    T: Send + Sync + 'static, 
[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]

impl<'de, T> Deserialize<'de> for Prefab<T> where
    T: Deserialize<'de>, 
[src]

Auto Trait Implementations

impl<T> Unpin for Prefab<T> where
    T: Unpin

impl<T> Sync for Prefab<T> where
    T: Sync

impl<T> Send for Prefab<T> where
    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]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

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]

impl<T> DeserializeOwned for T where
    T: Deserialize<'de>, 
[src]

impl<T> Resource for T where
    T: Any + Send + Sync
[src]

impl<T> Any for T where
    T: Any
[src]

impl<T> TryDefault for T where
    T: Default
[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]

impl<T> Erased for T[src]

impl<T> Serialize for T where
    T: Serialize + ?Sized
[src]