mirror of
https://github.com/bevyengine/bevy
synced 2025-02-16 14:08:32 +00:00
fix example custom_asset_reader on wasm (#10574)
# Objective - Example `custom_asset_reader` fails to build in wasm ``` $ cargo build --profile release --target wasm32-unknown-unknown --example custom_asset_reader Compiling bevy v0.12.0 (/Users/runner/work/bevy-website/bevy-website) error[E0432]: unresolved import `bevy::asset::io::file` --> examples/asset/custom_asset_reader.rs:7:9 | 7 | file::FileAssetReader, AssetReader, AssetReaderError, AssetSource, AssetSourceId, | ``` ## Solution - Wrap the platform default asset reader instead of the `FileAssetReader`
This commit is contained in:
parent
ce69959a69
commit
387755748c
1 changed files with 9 additions and 8 deletions
|
@ -3,19 +3,16 @@
|
|||
//! It does not know anything about the asset formats, only how to talk to the underlying storage.
|
||||
|
||||
use bevy::{
|
||||
asset::io::{
|
||||
file::FileAssetReader, AssetReader, AssetReaderError, AssetSource, AssetSourceId,
|
||||
PathStream, Reader,
|
||||
},
|
||||
asset::io::{AssetReader, AssetReaderError, AssetSource, AssetSourceId, PathStream, Reader},
|
||||
prelude::*,
|
||||
utils::BoxedFuture,
|
||||
};
|
||||
use std::path::Path;
|
||||
|
||||
/// A custom asset reader implementation that wraps a given asset reader implementation
|
||||
struct CustomAssetReader<T: AssetReader>(T);
|
||||
struct CustomAssetReader(Box<dyn AssetReader>);
|
||||
|
||||
impl<T: AssetReader> AssetReader for CustomAssetReader<T> {
|
||||
impl AssetReader for CustomAssetReader {
|
||||
fn read<'a>(
|
||||
&'a self,
|
||||
path: &'a Path,
|
||||
|
@ -52,8 +49,12 @@ impl Plugin for CustomAssetReaderPlugin {
|
|||
fn build(&self, app: &mut App) {
|
||||
app.register_asset_source(
|
||||
AssetSourceId::Default,
|
||||
AssetSource::build()
|
||||
.with_reader(|| Box::new(CustomAssetReader(FileAssetReader::new("assets")))),
|
||||
AssetSource::build().with_reader(|| {
|
||||
Box::new(CustomAssetReader(
|
||||
// This is the default reader for the current platform
|
||||
AssetSource::get_default_reader("assets".to_string())(),
|
||||
))
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue