NiklasEi / bevy_asset_loader

Bevy plugin helping with asset loading and organization
Apache License 2.0
482 stars 53 forks source link

Add a asset url prefix #102

Closed CodingJinxx closed 1 year ago

CodingJinxx commented 1 year ago

Adding a Optional Prefix to asset urls allows easier integration for Bevy WASM into existing Webtechnologies. For example in my case i had to prefix my asset path with _content because blazors routing ended up placing my assets at that url. Adding a simple method to the builder would allow me to do this

            LoadingState::new(GameState::Loading)
                .withPrefix("_content/BlazoredBevy.UI/assets")
                .with_collection::<FontAssets>()
                .with_collection::<AudioAssets>()
                .with_collection::<TextureAssets>()
                .continue_to_state(GameState::Menu)

instead of:

#[derive(AssetCollection, Resource)]
pub struct FontAssets {
    #[asset(path = "_content/BlazoredBevy.UI/assets/fonts/FiraSans-Bold.ttf")]
    pub fira_sans: Handle<Font>,
}
NiklasEi commented 1 year ago

This might be much nicer solved by setting the asset_folder as part of the AssetPlugin to be _content/BlazoredBevy.UI/assets. Have you tried that?

NiklasEi commented 1 year ago

I close this for now. If the proposed solution doesn't work or you see any other reason why this requires changes in bevy_asset_loader, feel free to comment and reopen the issue 🙂