Replies: 1 comment 3 replies
-
I think I found a possible solution: impl AssetLoader for CustomAssetLoader {
fn load<'a>(
&'a self,
bytes: &'a [u8],
load_context: &'a mut LoadContext,
) -> BoxedFuture<'a, anyhow::Result<(), anyhow::Error>> {
Box::pin(async move {
// Load file
let config = ron::de::from_bytes::<CustomAssetConfig>(bytes)?;
let path = Path::new(&config.texture);
// Stolen from `ImageTextureLoader`
let img_bytes = load_context.read_asset_bytes(path.clone()).await?;
let ext = path.extension().unwrap().to_str().unwrap();
let dyn_img = Texture::from_buffer(&img_bytes, ImageType::Extension(ext))?;
// Create asset
let handle = load_context.set_labeled_asset("foo", LoadedAsset::new(dyn_img));
let asset = LoadedAsset::new(CustomAsset { texture_handle: handle });
load_context.set_default_asset(asset);
Ok(())
})
}
fn extensions(&self) -> &[&str] {
&["ron"]
}
} Is this the best way to go about it? (If so, I'll mark this as the answer) |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
For example, say I have a config file:
And I want to load this in as an Asset using a custom
AssetLoader
. How do I also load the texture (or any other sub-assets) along with it?Beta Was this translation helpful? Give feedback.
All reactions