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
//! 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;
//! # use bevy::state::app::StatesPlugin;
//! fn main() {
//! App::new()
//! # /*
//! .add_plugins(DefaultPlugins)
//! # */
//! # .add_plugins((MinimalPlugins, AssetPlugin::default(), StatesPlugin))
//! .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(); AppExit::Success})
//! .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(AudioPlayer(audio_assets.background.clone()));
//! }
//!
//! #[derive(Clone, Eq, PartialEq, Debug, Hash, Default, States)]
//! enum GameState {
//! #[default]
//! Loading,
//! Next
//! }
//! ```
/// Trait definition for types that represent a collection of assets
///
/// And extension traits to insert said collections into your Bevy app or world
/// Types and infrastructure to load and use dynamic assets
/// A game state responsible for loading assets
/// Trait definition for mapped assets collection
/// Dynamic assets for common Bevy asset types
/// Most commonly used types
;