Class AddressableAssetService
This implementation of IAssetService uses Unity's Addressable Assets as a backend. Assets are managed in the Addressable Asset Settings via the Addressables Editor Windows and this service loads and unloads them from there. Assets loaded with this service are injected the first time they are loaded if possible.
Inherited Members
Namespace: IdleKit.Core
Assembly: cs.temp.dll.dll
Syntax
public class AddressableAssetService : ServiceBase, IAssetService, IService, IInjectable
Fields
_loadedAssetHandles
Declaration
protected Dictionary<string, AsyncOperationHandle> _loadedAssetHandles
Field Value
Type | Description |
---|---|
Dictionary<String, AsyncOperationHandle> |
_normalizedProgress
Declaration
protected float _normalizedProgress
Field Value
Type | Description |
---|---|
Single |
_resolver
Declaration
protected IResolver _resolver
Field Value
Type | Description |
---|---|
IResolver |
Properties
NormalizedProgress
Declaration
public virtual float NormalizedProgress { get; }
Property Value
Type | Description |
---|---|
Single |
Methods
AddAssets(String, IEnumerable<Object>)
Stores one or more assets under a key to be returned by a load operation.
Declaration
public virtual void AddAssets(string key, IEnumerable<object> assets)
Parameters
Type | Name | Description |
---|---|---|
String | key | The key to store the assets under. A load operation that is passed the same key should return these assets. |
IEnumerable<Object> | assets | The assets to store. |
CleanupService()
Declaration
protected override void CleanupService()
Overrides
InitializeService()
Declaration
protected override void InitializeService()
Overrides
Inject(IResolver)
Allow the IResolver be injected into this IInjectable class and then the IInjectable class would be able to fetch its dependencies using the IResolver. It is done this way in IdleKit for simplicity and to avoid using System.Reflection
Declaration
public override void Inject(IResolver resolver)
Parameters
Type | Name | Description |
---|---|---|
IResolver | resolver | the IResolver that is being injected |
Overrides
LoadAssetReferences<TAsset>(IEnumerable<IAssetReference<TAsset>>, Action<List<TAsset>>)
Declaration
public virtual void LoadAssetReferences<TAsset>(IEnumerable<IAssetReference<TAsset>> assetReferences, Action<List<TAsset>> onComplete)
where TAsset : class
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<IAssetReference<TAsset>> | assetReferences | |
Action<List<TAsset>> | onComplete |
Type Parameters
Name | Description |
---|---|
TAsset |
LoadAssets(String, Action<List<Object>>)
Loaded assets will be injected with IResolver if they implement IInjectable.
Declaration
public virtual void LoadAssets(string key, Action<List<object>> onComplete)
Parameters
Type | Name | Description |
---|---|---|
String | key | The key to load the assets from. |
Action<List<Object>> | onComplete | Broadcast when the assets have been loaded. |
LoadAssets(Type, String, Action<List<Object>>)
Loaded assets will be injected with IResolver if they implement IInjectable.
Declaration
public virtual void LoadAssets(Type assetType, string key, Action<List<object>> onComplete)
Parameters
Type | Name | Description |
---|---|---|
Type | assetType | The Type of asset to load. |
String | key | The key to load the assets from. |
Action<List<Object>> | onComplete | Broadcast when the assets have been loaded. |
LoadAssets<TResult>(String, Action<List<TResult>>)
Loaded assets will be injected with IResolver if they implement IInjectable.
Declaration
public virtual void LoadAssets<TResult>(string key, Action<List<TResult>> onComplete)
where TResult : class
Parameters
Type | Name | Description |
---|---|---|
String | key | |
Action<List<TResult>> | onComplete |
Type Parameters
Name | Description |
---|---|
TResult |
LoadAssetsInternal(Type, String, Action<List<Object>>)
This is the central load method. All other load methods load assets through this method.
Declaration
protected virtual void LoadAssetsInternal(Type assetType, string key, Action<List<object>> onComplete)
Parameters
Type | Name | Description |
---|---|---|
Type | assetType | |
String | key | |
Action<List<Object>> | onComplete |
RemoveAllAssets()
Remove all assets.
Declaration
public virtual void RemoveAllAssets()
RemoveAssets(String, IEnumerable<Object>)
Removes one or more assets under a specific key that have previously been added so they can no longer be loaded.
Declaration
public virtual void RemoveAssets(string key, IEnumerable<object> assets)
Parameters
Type | Name | Description |
---|---|---|
String | key | The key to remove the assets from under. |
IEnumerable<Object> | assets | The assets to remove. |
UnloadAllAssets()
Unload all assets.
Declaration
public virtual void UnloadAllAssets()
UnloadAssetReferences<TAsset>(IEnumerable<IAssetReference<TAsset>>)
Declaration
public virtual void UnloadAssetReferences<TAsset>(IEnumerable<IAssetReference<TAsset>> assetReferences)
where TAsset : class
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<IAssetReference<TAsset>> | assetReferences |
Type Parameters
Name | Description |
---|---|
TAsset |
UnloadAssets(String)
Unloads one or more assets.
Declaration
public virtual void UnloadAssets(string key)
Parameters
Type | Name | Description |
---|---|---|
String | key | The key to unload the assets from. |
UnloadAssetsInternal(String)
This is the central unload method. All other load methods unload assets through this method.
Declaration
protected virtual void UnloadAssetsInternal(string key)
Parameters
Type | Name | Description |
---|---|---|
String | key |