1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
//! The goal of this crate is to offer an easy way for bevy games to load all their assets in a loading [`State`](::bevy::ecs::schedule::State).
//!
//! `bevy_asset_loader` introduces the derivable trait [`AssetCollection`](crate::asset_collection::AssetCollection). Structs with asset handles
//! can be automatically loaded during a configurable loading [`State`](::bevy::ecs::schedule::State). Afterwards they will be inserted as
//! resources containing loaded handles and the plugin will switch to a second configurable [`State`](::bevy::ecs::schedule::State).
//!
//! ```edition2021
//! # use bevy_asset_loader::prelude::*;
//! # use bevy::prelude::*;
//! # use bevy::asset::AssetPlugin;
//!
//! fn main() {
//! App::new()
//! # /*
//! .add_plugins(DefaultPlugins)
//! # */
//! # .add_plugins((MinimalPlugins, AssetPlugin::default()))
//! # .init_resource::<iyes_progress::ProgressCounter>()
//! .init_state::<GameState>()
//! .add_loading_state(
//! LoadingState::new(GameState::Loading)
//! .continue_to_state(GameState::Next)
//! .load_collection::<AudioAssets>()
//! .load_collection::<ImageAssets>()
//! )
//! .add_systems(Update, use_asset_handles.run_if(in_state(GameState::Next)))
//! # .set_runner(|mut app| app.update())
//! .run();
//! }
//!
//! #[derive(AssetCollection, Resource)]
//! struct AudioAssets {
//! #[asset(path = "audio/background.ogg")]
//! background: Handle<AudioSource>,
//! #[asset(path = "audio/plop.ogg")]
//! plop: Handle<AudioSource>
//! }
//!
//! #[derive(AssetCollection, Resource)]
//! pub struct ImageAssets {
//! #[asset(path = "images/player.png")]
//! pub player: Handle<Image>,
//! #[asset(path = "images/tree.png")]
//! pub tree: Handle<Image>,
//! }
//!
//! // since this function runs in MyState::Next, we know our assets are loaded.
//! // We can get their handles from the AudioAssets resource.
//! fn use_asset_handles(mut commands: Commands, audio_assets: Res<AudioAssets>) {
//! commands.spawn(AudioBundle {
//! source: audio_assets.background.clone(),
//! ..default()
//! });
//! }
//!
//! #[derive(Clone, Eq, PartialEq, Debug, Hash, Default, States)]
//! enum GameState {
//! #[default]
//! Loading,
//! Next
//! }
//! ```
#![forbid(unsafe_code)]
#![warn(unused_imports, missing_docs)]
#![cfg_attr(docsrs, feature(doc_cfg))]
/// Trait definition for types that represent a collection of assets
///
/// And extension traits to insert said collections into your Bevy app or world
pub mod asset_collection;
/// Types and infrastructure to load and use dynamic assets
pub mod dynamic_asset;
/// A game state responsible for loading assets
pub mod loading_state;
/// Trait definition for mapped assets collection
pub mod mapped;
/// Dynamic assets for common Bevy asset types
#[cfg_attr(docsrs, doc(cfg(feature = "standard_dynamic_assets")))]
#[cfg(feature = "standard_dynamic_assets")]
pub mod standard_dynamic_asset;
/// Most commonly used types
pub mod prelude {
#[doc(hidden)]
pub use crate::loading_state::config::{ConfigureLoadingState, LoadingStateConfig};
#[doc(hidden)]
#[cfg(feature = "standard_dynamic_assets")]
pub use crate::standard_dynamic_asset::{
RegisterStandardDynamicAsset, StandardDynamicAsset, StandardDynamicAssetCollection,
};
#[doc(hidden)]
pub use crate::{
asset_collection::{AssetCollection, AssetCollectionApp, AssetCollectionWorld},
dynamic_asset::{
DynamicAsset, DynamicAssetCollection, DynamicAssetCollections, DynamicAssetType,
DynamicAssets,
},
loading_state::{LoadingState, LoadingStateAppExt, LoadingStateSet},
mapped::{FileName, FileStem, MapKey},
};
}
#[cfg(all(feature = "2d", feature = "3d"))]
#[doc = include_str!("../../README.md")]
#[cfg(doctest)]
struct ReadmeDoctests;