have a problem
This commit is contained in:
parent
5c1320d614
commit
011f8ce97b
@ -1,17 +1,23 @@
|
||||
use alloc::vec::Vec;
|
||||
|
||||
use crate::{Asset, UntypedHandle};
|
||||
use crate::{Asset, AssetPath, UntypedHandle};
|
||||
use bevy_reflect::TypePath;
|
||||
|
||||
pub struct LoadBatchRequest {
|
||||
pub requests: Vec<&'static str>,
|
||||
pub requests: Vec<AssetPath<'static>>,
|
||||
}
|
||||
|
||||
impl LoadBatchRequest {
|
||||
pub fn new(requests: Vec<&'static str>) -> Self {
|
||||
Self { requests }
|
||||
pub fn new<T>(requests: Vec<T>) -> Self
|
||||
where
|
||||
T:Into<AssetPath<'static>>,
|
||||
{
|
||||
Self {
|
||||
requests: requests.into_iter().map(Into::into).collect(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A "loaded batch" containing handles for all assets stored in a given [`AssetPath`].
|
||||
///
|
||||
/// This is produced by [`AssetServer::load_batch`](crate::prelude::AssetServer::load_batch).
|
||||
|
||||
@ -8,8 +8,12 @@ use bevy::{
|
||||
},
|
||||
prelude::*,
|
||||
};
|
||||
use bevy_asset::{LoadBatchRequest, LoadedBatch};
|
||||
use std::path::Path;
|
||||
|
||||
#[derive(Resource, Default)]
|
||||
struct SpriteBatch(Handle<LoadedBatch>);
|
||||
|
||||
fn main() {
|
||||
App::new()
|
||||
// Add an extra asset source with the name "example_files" to
|
||||
@ -43,4 +47,11 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
|
||||
assert_eq!(asset_path, "example_files://bevy_pixel_light.png".into());
|
||||
|
||||
commands.spawn(Sprite::from_image(asset_server.load(asset_path)));
|
||||
|
||||
let path = Path::new("*.png");
|
||||
let source = AssetSourceId::from("example_files");
|
||||
let asset_path = AssetPath::from_path(path).with_source(source);
|
||||
commands.insert_resource(SpriteBatch(
|
||||
asset_server.load_batch(LoadBatchRequest::new(vec![asset_path])),
|
||||
));
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user