loading.rs (1332B)
1 use crate::GameState; 2 use bevy::prelude::*; 3 use bevy_asset_loader::{AssetCollection, AssetLoader}; 4 use bevy_kira_audio::AudioSource; 5 6 pub struct LoadingPlugin; 7 8 /// This plugin loads all assets using [AssetLoader] from a third party bevy plugin 9 /// Alternatively you can write the logic to load assets yourself 10 /// If interested, take a look at https://bevy-cheatbook.github.io/features/assets.html 11 impl Plugin for LoadingPlugin { 12 fn build(&self, app: &mut App) { 13 AssetLoader::new(GameState::Loading) 14 .with_collection::<FontAssets>() 15 .with_collection::<AudioAssets>() 16 .with_collection::<TextureAssets>() 17 .continue_to_state(GameState::Menu) 18 .build(app); 19 } 20 } 21 22 // the following asset collections will be loaded during the State `GameState::Loading` 23 // when done loading, they will be inserted as resources (see https://github.com/NiklasEi/bevy_asset_loader) 24 25 #[derive(AssetCollection)] 26 pub struct FontAssets { 27 #[asset(path = "fonts/FiraSans-Bold.ttf")] 28 pub fira_sans: Handle<Font>, 29 } 30 31 #[derive(AssetCollection)] 32 pub struct AudioAssets { 33 #[asset(path = "audio/flying.ogg")] 34 pub flying: Handle<AudioSource>, 35 } 36 37 #[derive(AssetCollection)] 38 pub struct TextureAssets { 39 #[asset(path = "textures/bevy.png")] 40 pub texture_bevy: Handle<Image>, 41 }