This commit is contained in:
shishanyue 2025-06-19 00:05:12 +08:00
parent 7e51fc0749
commit c29cbcbf35
6 changed files with 14 additions and 10 deletions

View File

@ -15,5 +15,5 @@ pub struct LoadedFolder {
/// The handles of all assets stored in the folder.
#[dependency]
pub handles: Vec<UntypedHandle>,
pub filter: Option<Arc<dyn Fn(&Path,bool) -> bool + Send + Sync + 'static>>
pub filter: Option<Arc<dyn Fn(&Path, bool) -> bool + Send + Sync + 'static>>,
}

View File

@ -1618,7 +1618,7 @@ mod tests {
.init_asset::<SubText>()
.register_asset_loader(CoolTextLoader);
let asset_server = app.world().resource::<AssetServer>().clone();
let handle: Handle<LoadedFolder> = asset_server.load_folder("text",None);
let handle: Handle<LoadedFolder> = asset_server.load_folder("text", None);
gate_opener.open(a_path);
gate_opener.open(b_path);
gate_opener.open(c_path);

View File

@ -31,7 +31,9 @@ struct RpgSpriteFolder(Handle<LoadedFolder>);
fn load_textures(mut commands: Commands, asset_server: Res<AssetServer>) {
// Load multiple, individual sprites from a folder
commands.insert_resource(RpgSpriteFolder(asset_server.load_folder("textures/rpg",None)));
commands.insert_resource(RpgSpriteFolder(
asset_server.load_folder("textures/rpg", None),
));
}
fn check_textures(

View File

@ -254,6 +254,7 @@ Example | Description
[Custom Asset IO](../examples/asset/custom_asset_reader.rs) | Implements a custom AssetReader
[Embedded Asset](../examples/asset/embedded_asset.rs) | Embed an asset in the application binary and load it
[Extra asset source](../examples/asset/extra_source.rs) | Load an asset from a non-standard asset source
[Folder Filter](../examples/asset/folder_filter.rs) | Load Folder With Filter
[Hot Reloading of Assets](../examples/asset/hot_asset_reloading.rs) | Demonstrates automatic reloading of assets when modified on disk
[Multi-asset synchronization](../examples/asset/multi_asset_sync.rs) | Demonstrates how to wait for multiple assets to be loaded.
[Repeated texture configuration](../examples/asset/repeated_texture.rs) | How to configure the texture to repeat instead of the default clamp to edges

View File

@ -52,7 +52,7 @@ fn setup(
// to load.
// If you want to keep the assets in the folder alive, make sure you store the returned handle
// somewhere.
let _loaded_folder: Handle<LoadedFolder> = asset_server.load_folder("models/torus",None);
let _loaded_folder: Handle<LoadedFolder> = asset_server.load_folder("models/torus", None);
// If you want a handle to a specific asset in a loaded folder, the easiest way to get one is to call load.
// It will _not_ be loaded a second time.

View File

@ -1,5 +1,6 @@
//! In this example we generate four texture atlases (sprite sheets) from a folder containing
//! individual sprites.
//! individual sprites.But the folder containing waste files called "waste.txt"
//! So we use filter to ingrone the waste files
//!
//! The texture atlases are generated with different padding and sampling to demonstrate the
//! effect of these settings, and how bleeding issues can be resolved by padding the sprites.
@ -35,11 +36,11 @@ fn load_textures(mut commands: Commands, asset_server: Res<AssetServer>) {
// Load multiple, individual sprites from a folder
commands.insert_resource(RpgSpriteFolder(asset_server.load_folder(
"textures/rpg_with_waste",
Some(Arc::new(|path,is_dir| {
let a = is_dir || path.extension().unwrap_or_default() == "png";
info!("is_dir:{},path:{:?} {}",is_dir,path,a);
a
})),
Some(Arc::new(|path, is_dir| {
let need = is_dir || path.extension().unwrap_or_default() == "png";
info!("is_dir:{} path:{:?} need:{}", is_dir, path, need);
need
})),
)));
}