Struct bevy_asset_loader::AssetLoader [−][src]
pub struct AssetLoader<T> { /* fields omitted */ }
Expand description
A Bevy plugin to configure automatic asset loading
fn main() { let mut app = App::build(); AssetLoader::new(GameState::Loading, GameState::Menu) .with_collection::<AudioAssets>() .with_collection::<TextureAssets>() .build(&mut app); app.add_state(GameState::Loading) .add_plugins(MinimalPlugins) .add_plugin(AssetPlugin::default()) .add_system_set(SystemSet::on_enter(GameState::Menu) .with_system(play_audio.system()) ) .run(); } fn play_audio(audio_assets: Res<AudioAssets>, audio: Res<Audio>) { audio.play(audio_assets.flying.clone()); } #[derive(Clone, Eq, PartialEq, Debug, Hash)] enum GameState { Loading, Menu } #[derive(AssetCollection)] pub struct AudioAssets { #[asset(path = "audio/background.ogg")] pub background: Handle<AudioSource>, } #[derive(AssetCollection)] pub struct TextureAssets { #[asset(path = "textures/player.png")] pub player: Handle<Texture>, #[asset(path = "textures/tree.png")] pub tree: Handle<Texture>, }
Implementations
Create a new AssetLoader
This function takes two States. During the first all assets will be loaded and the collections will be inserted as resources. Then the second state is set in your Bevy App.
let mut app = App::build(); AssetLoader::new(GameState::Loading, GameState::Menu) .with_collection::<AudioAssets>() .with_collection::<TextureAssets>() .build(&mut app);
Add an AssetCollection to the AssetLoader
The added collection will be loaded and inserted into your Bevy App as a resource.
let mut app = App::build(); AssetLoader::new(GameState::Loading, GameState::Menu) .with_collection::<AudioAssets>() .with_collection::<TextureAssets>() .build(&mut app);
Finish configuring the AssetLoader
Calling this function is required to set up the asset loading.
let mut app = App::build(); AssetLoader::new(GameState::Loading, GameState::Menu) .with_collection::<AudioAssets>() .with_collection::<TextureAssets>() .build(&mut app);
Auto Trait Implementations
impl<T> !RefUnwindSafe for AssetLoader<T>
impl<T> Send for AssetLoader<T> where
T: Send,
impl<T> Sync for AssetLoader<T> where
T: Sync,
impl<T> Unpin for AssetLoader<T> where
T: Unpin,
impl<T> !UnwindSafe for AssetLoader<T>
Blanket Implementations
Mutably borrows from an owned value. Read more
impl<T> Downcast for T where
T: Any,
impl<T> Downcast for T where
T: Any,
Convert Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
. Read more
pub fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
pub fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
Convert Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
. Read more
Convert &Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s. Read more
pub fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
pub fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert &mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s. Read more
Instruments this type with the provided Span
, returning an
Instrumented
wrapper. Read more
pub fn vzip(self) -> V