Add load_untyped
to LoadContext (#10526)
# Objective Give us the ability to load untyped assets in AssetLoaders. ## Solution Basically just copied the code from `load`, but used `asset_server.load_untyped` instead internally. ## Changelog Added `load_untyped` method to `LoadContext`
This commit is contained in:
parent
520a09a083
commit
ce69959a69
@ -5,8 +5,8 @@ use crate::{
|
||||
Settings,
|
||||
},
|
||||
path::AssetPath,
|
||||
Asset, AssetLoadError, AssetServer, AssetServerMode, Assets, Handle, UntypedAssetId,
|
||||
UntypedHandle,
|
||||
Asset, AssetLoadError, AssetServer, AssetServerMode, Assets, Handle, LoadedUntypedAsset,
|
||||
UntypedAssetId, UntypedHandle,
|
||||
};
|
||||
use bevy_ecs::world::World;
|
||||
use bevy_utils::{BoxedFuture, CowArc, HashMap, HashSet};
|
||||
@ -462,6 +462,21 @@ impl<'a> LoadContext<'a> {
|
||||
handle
|
||||
}
|
||||
|
||||
/// Retrieves a handle for the asset at the given path and adds that path as a dependency of the asset without knowing its type.
|
||||
pub fn load_untyped<'b>(
|
||||
&mut self,
|
||||
path: impl Into<AssetPath<'b>>,
|
||||
) -> Handle<LoadedUntypedAsset> {
|
||||
let path = path.into().to_owned();
|
||||
let handle = if self.should_load_dependencies {
|
||||
self.asset_server.load_untyped(path)
|
||||
} else {
|
||||
self.asset_server.get_or_create_path_handle(path, None)
|
||||
};
|
||||
self.dependencies.insert(handle.id().untyped());
|
||||
handle
|
||||
}
|
||||
|
||||
/// Loads the [`Asset`] of type `A` at the given `path` with the given [`AssetLoader::Settings`] settings `S`. This is a "deferred"
|
||||
/// load. If the settings type `S` does not match the settings expected by `A`'s asset loader, an error will be printed to the log
|
||||
/// and the asset load will fail.
|
||||
|
Loading…
Reference in New Issue
Block a user