Add reload_asset method to AssetServer. (#5106)

# Objective

Add support for custom `AssetIo` implementations to trigger reloading of an asset.

## Solution

- Add a public method to `AssetServer` to allow forcing the reloading of an asset.

---

## Changelog

- Add method `reload_asset` to `AssetServer`.


Co-authored-by: Robert G. Jakabosky <rjakabosky+neopallium@neoawareness.com>
This commit is contained in:
Robert Gabriel Jakabosky 2022-06-26 21:45:04 +00:00
parent a32eac825a
commit a138804d61

View file

@ -371,6 +371,14 @@ impl AssetServer {
self.get_handle_untyped(handle_id) self.get_handle_untyped(handle_id)
} }
/// Force an [`Asset`] to be reloaded.
///
/// This is useful for custom hot-reloading or for supporting `watch_for_changes`
/// in custom [`AssetIo`] implementations.
pub fn reload_asset<'a, P: Into<AssetPath<'a>>>(&self, path: P) {
self.load_untracked(path.into(), true);
}
pub(crate) fn load_untracked(&self, asset_path: AssetPath<'_>, force: bool) -> HandleId { pub(crate) fn load_untracked(&self, asset_path: AssetPath<'_>, force: bool) -> HandleId {
let server = self.clone(); let server = self.clone();
let owned_path = asset_path.to_owned(); let owned_path = asset_path.to_owned();