vleue / bevy_embedded_assets

Bevy plugin to embed assets in your game

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support Bevy 0.12?

zachbateman opened this issue · comments

It looks like Bevy 0.12 includes some support for embedded assets: https://bevyengine.org/news/bevy-0-12/#embedded-assets

That said, this crate has been working great for me, and I'm having trouble trying to get the Bevy 0.12 embedded assets working as a replacement. Should/can this crate be updated to support Bevy 0.12, or should we switch to using Bevy itself for embedded assets?

The embedded_asset! macro is intended to be used in shader scripts and things that is on src I managed to make it work but is very trick, I think they have to change this.

What I recommend you doing is using what is inside the macro.

let embedded = app.world.resource_mut::<EmbeddedAssetRegistry>();
embedded.insert_asset(
    PathBuf::new(),
    Path::new("sprites.png"),
    include_bytes!("../assets/sprites.png"),
);

The second argument is like a “key” it can have any name you want and will be used to load the asset asset_server.load("embedded://sprites.png")

About upgrading this crate, I think this will be difficult since this crate use things that don't have a proper documentation, and they have made big changes on asset loading

Maybe this crate can check the assets folder and do something familiar to what I have showed, but to all files in the asset folder.

I made a more useful macro:

macro_rules! embedded_asset {
    ($embedded:ident, $path:expr) => {
        $embedded.insert_asset(
            PathBuf::new(),
            Path::new($path),
            include_bytes!(concat!("../assets/", $path)),
        );
    };
}

struct EmbeddedAssetsPlugin;

impl Plugin for EmbeddedAssetsPlugin {
    fn build(&self, app: &mut App) {
        let embedded = app.world.resource_mut::<EmbeddedAssetRegistry>();
        embedded_asset!(embedded, "sprites.png");
    }
}

I'll try to upgrade this crate, if only to have the build script that automatically embed all the assets folder for you 👍

I'll take a look this week end

I just released version 0.9, with support for Bevy 0.12.

By default it will use the new embedded:// asset source, but can be configured to use the default one (just the file path)

Thanks so much for the update, @mockersf! I tweaked a few things for my project in #16.