AssetStorage
Asynchronous asset loader based on coroutines API. An AssetManager alternative.
Note that KtxAsync.initiate must be called on the rendering thread before creating an AssetStorage.
asyncContext is used to perform asynchronous file loading. Defaults to a single-threaded context using an AsyncExecutor. See newSingleThreadAsyncContext or ktx.async.newAsyncContext functions to create a custom loading context. Multithreaded contexts are fully supported and might boost loading performance if the assets are loaded asynchronously in parallel.
fileResolver determines how file paths are interpreted. Defaults to InternalFileHandleResolver, which loads internal files.
If useDefaultLoaders
is true (which is the default), all default libGDX AssetLoader implementations will be registered. If silenceAssetManagerWarnings is false (which is the default), all non-fatal asset loading issues caused by asset loaders will be logged as errors. It is encouraged not to change this setting to true during the development to avoid potential errors.
Constructors
Properties
Functions
Adds a fully loaded asset to the storage. Allows to avoid loading the asset with the AssetStorage and to manually add it to storage context.
Checks whether an asset described by descriptor is currently managed by the storage. This will return true for assets that are currently being loaded or
Checks whether an asset in the selected path and T type is currently managed by the storage. This will return true for assets that are currently being loaded or
Checks whether an asset identified by identifier is currently managed by the storage. This will return true for assets that are currently being loaded or
Unloads all assets. Blocks current thread until are assets are unloaded. Logs all disposing exceptions.
Unloads all assets. Cancels loading of all scheduled assets. onError will be invoked on every caught disposing exception.
Returns a loaded asset of type T described by descriptor or throws MissingAssetException if the asset is not loaded yet or was never scheduled for loading. Rethrows any exceptions encountered during asset loading.
Returns a loaded asset of type T loaded from selected path or throws MissingAssetException if the asset is not loaded yet or was never scheduled for loading. Rethrows any exceptions encountered during asset loading.
Returns a loaded asset of type T identified by identifier or throws MissingAssetException if the asset is not loaded yet or was never scheduled for loading. Rethrows any exceptions encountered during asset loading.
Creates a new AssetDescriptor for the selected asset.
Internal utility method. Returns a list of asset Identifiers associated with the asset path. Do not attempt to modify the returned list. Changing the list might have an unpredictable effect on the asset loaders.
Returns the reference to the asset wrapped with Deferred. Use Deferred.await to obtain the instance. Throws AssetStorageException if the asset was unloaded or never scheduled to begin with.
Returns the reference to the asset wrapped with Deferred. Use Deferred.await to obtain the instance.
Returns a copy of the list of dependencies of the asset described by descriptor. If the asset is not loaded or has no dependencies, an empty list is returned.
Returns a copy of the list of dependencies of the asset under path with T type. If the asset is not loaded or has no dependencies, an empty list is returned.
Returns a copy of the list of dependencies of the asset identified by identifier. If the asset is not loaded or has no dependencies, an empty list is returned.
Creates a new Identifier that allows to uniquely describe an asset by path and class. Uses reified T type to obtain the asset class.
Returns a loaded asset of type T described by descriptor or null
if the asset is not loaded yet or was never scheduled for loading. Rethrows any exceptions encountered during asset loading.
Returns a loaded asset of type T loaded from selected path or null
if the asset is not loaded yet or was never scheduled for loading. Rethrows any exceptions encountered during asset loading.
Returns a loaded asset of type T identified by identifier or null
if the asset is not loaded yet or was never scheduled for loading. Rethrows any exceptions encountered during asset loading.
Returns the amount of references to the asset described by descriptor.
Returns the amount of references to the asset identified by identifier.
Checks whether an asset described with descriptor is already loaded. Returns false if the asset is not loaded yet, is unloaded or was never loaded to begin with.
Checks whether an asset in the selected path with T type is already loaded. Returns false if the asset is not loaded yet, is unloaded or was never loaded to begin with.
Checks whether an asset identified with identifier is already loaded. Returns false if the asset is not loaded yet, is unloaded or was never loaded to begin with.
Schedules loading of an asset of T type described by the descriptor. Suspends the coroutine until an asset is loaded and returns a fully loaded instance of T.
Schedules loading of an asset of T type located at path. Suspends the coroutine until an asset is loaded and returns a fully loaded instance of T.
Schedules loading of an asset with path and type specified by identifier. Suspends the coroutine until an asset is loaded and returns a fully loaded instance of T.
Schedules loading of an asset of T type described by the descriptor. Suspends the coroutine until an asset is loaded and returns a fully loaded instance of T.
Schedules asynchronous loading of an asset of T type located at path. Return a Deferred reference which will eventually point to a fully loaded instance of T.
Schedules loading of an asset with path and type specified by identifier. Suspends the coroutine until an asset is loaded and returns a fully loaded instance of T.
Blocks the current thread until the asset with T type is loaded using the asset descriptor.
Blocks the current thread until the asset with T type is loaded with data specified by the identifier and optional loading parameters.
Matches AssetDescriptor pre-processing. Return this String with normalized file separators.
Associates the AssetLoader with specific asset type determined by T. loaderProvider should create a new instance of loader of the selected types. Optional suffix can be passed if the loader should handle only the files with a specific file name suffix or extension.
Internal API exposed for inlined method. See inlined setLoader with reified generics. Associates the AssetLoader with type under the specified optional suffix.
Creates a deep copy of the internal asset storage. Returns an AssetStorageSnapshot with the current storage state. Blocks the current thread until the snapshot is complete. If assets are currently being loaded, avoid calling this method from within the rendering thread. For debugging purposes.
Creates a deep copy of the internal asset storage. Returns an AssetStorageSnapshot with the current storage state. For debugging purposes.
Removes asset described by the descriptor and all of its dependencies. Does nothing if asset was not loaded in the first place. Will not dispose of the asset if it still is referenced by any other assets. Any removed assets that implement Disposable will be disposed.
Removes asset loaded with the given path and T type and all of its dependencies. Does nothing if asset was not loaded in the first place. Will not dispose of the asset if it still is referenced by any other assets. Any removed assets that implement Disposable will be disposed.
Removes asset loaded with the given identifier and all of its dependencies. Does nothing if asset was not loaded in the first place. Will not dispose of the asset if it still is referenced by any other assets. Any removed assets that implement Disposable will be disposed.