Addressable Assets¶
Any tools to assist with the usage of Addressable Assets can be found here.
Addressable Cache Manager¶
The Addressable Cache Manager is a tool used to manage Unity's addressables assets from a central location. It allows us to load assets and store results in this one cache to easily retrieve and even be able to keep track of usage count for proper releasing. The Manager is instantiated as a GameObject for easy debugging so that you can see everything stored inside the manager from the editor window. Also OnDestroy()
of the GameObject, we clear all the assets from the cache.
The idea is to mimic from Addressables LoadAssetAsync
.
async LoadAssetAsync(AssetReference assetReference) : Task¶
Load the asset reference asynchronously and return the result. It will reload an asset if it failed to load previously. On success of loading the asset, we increment the usage count since this returns a result
async LoadAsset(AssetReference assetReference) : void¶
Load the asset but do not return the result. It will reload an asset if it failed to load previously. Count remains at zero but this is good to preload assets beforehand.
TryGetLoadedAsset(AssetReference assetReference, out T? result) : bool¶
Try and get the loaded asset from the cache. If the asset is not loaded, it will return false and the result will be null.
TryGetLoadedAssetWithResult(AssetReference assetReference, out T? result, out AddressablesCacheStatus status) : bool¶
Try and get the loaded asset from the cache. If the asset is not loaded, it will return false and the result will be null. The status will be set to the current status of the asset.
ReleaseAsset(AssetReference assetReference) : bool¶
Release the asset from the cache. This will decrement the usage count and if it reaches zero, it will unload the asset. Returns true if the asset was released successfully.
ReleaseAndClearAssets() : void¶
Release all assets from the cache and clear the cache.
AddressablesCacheStatus¶
- None: Not loaded at all
- Loading: In Progress
- Loaded: Completed and stored in cache
- Failed: Failed loading
AddressablesUtilsModule¶
Responsible for initializing the Addressable Cache Manager and storing it in ECS as a singleton.