Class ResourceManager
Entry point for ResourceManager API
Namespace: UnityEngine.ResourceManagement
Syntax
public class ResourceManager : IDisposable
Constructors
ResourceManager(IAllocationStrategy)
Constructor for the resource manager.
Declaration
public ResourceManager(IAllocationStrategy alloc = null)
Parameters
| Type | Name | Description |
|---|---|---|
| IAllocationStrategy | alloc | The allocation strategy to use. |
Properties
Allocator
The allocation strategy object.
Declaration
public IAllocationStrategy Allocator { get; set; }
Property Value
| Type | Description |
|---|---|
| IAllocationStrategy |
CertificateHandlerInstance
The CertificateHandler instance object.
Declaration
public CertificateHandler CertificateHandlerInstance { get; set; }
Property Value
| Type | Description |
|---|---|
| CertificateHandler |
ExceptionHandler
Global exception handler. This will be called whenever an IAsyncOperation.OperationException is set to a non-null value. See the ResourceManager.ExceptionHandler documentation for more details.
Declaration
public static Action<AsyncOperationHandle, Exception> ExceptionHandler { get; set; }
Property Value
| Type | Description |
|---|---|
| Action<AsyncOperationHandle, Exception> |
InternalIdTransformFunc
Functor to transform internal ids before being used by the providers. See the TransformInternalId documentation for more details.
Declaration
public Func<IResourceLocation, string> InternalIdTransformFunc { get; set; }
Property Value
| Type | Description |
|---|---|
| Func<IResourceLocation, String> |
ResourceProviders
Gets the list of configured IResourceProvider objects. Resource Providers handle load and release operations for IResourceLocation objects.
Declaration
public IList<IResourceProvider> ResourceProviders { get; }
Property Value
| Type | Description |
|---|---|
| IList<IResourceProvider> | The resource providers list. |
Methods
Acquire(AsyncOperationHandle)
Increment reference count of operation handle.
Declaration
public void Acquire(AsyncOperationHandle handle)
Parameters
| Type | Name | Description |
|---|---|---|
| AsyncOperationHandle | handle | The handle to the resource to increment the reference count for. |
AddUpdateReceiver(IUpdateReceiver)
Add an update reveiver.
Declaration
public void AddUpdateReceiver(IUpdateReceiver receiver)
Parameters
| Type | Name | Description |
|---|---|---|
| IUpdateReceiver | receiver | The object to add. The Update method will be called until the object is removed. |
CleanupSceneInstances(Scene)
Releases all instances the given scence.
Declaration
public void CleanupSceneInstances(Scene scene)
Parameters
| Type | Name | Description |
|---|---|---|
| Scene | scene | The scene whose instances should be released. |
ClearDiagnosticCallbacks()
Clears out the diagnostics callbacks handler.
Declaration
public void ClearDiagnosticCallbacks()
ClearDiagnosticsCallback()
Clears out the diagnostics callback handler.
Declaration
public void ClearDiagnosticsCallback()
CreateChainOperation<TObject>(AsyncOperationHandle, Func<AsyncOperationHandle, AsyncOperationHandle<TObject>>)
Create a chain operation to handle dependencies.
Declaration
public AsyncOperationHandle<TObject> CreateChainOperation<TObject>(AsyncOperationHandle dependentOp, Func<AsyncOperationHandle, AsyncOperationHandle<TObject>> callback)
Parameters
| Type | Name | Description |
|---|---|---|
| AsyncOperationHandle | dependentOp | The dependency operation. |
| Func<AsyncOperationHandle, AsyncOperationHandle<TObject>> | callback | The callback method that will create the dependent operation from the dependency operation. |
Returns
| Type | Description |
|---|---|
| AsyncOperationHandle<TObject> | The operation handle. |
Type Parameters
| Name | Description |
|---|---|
| TObject | The type of operation handle to return. |
CreateChainOperation<TObject>(AsyncOperationHandle, Func<AsyncOperationHandle, AsyncOperationHandle<TObject>>, Boolean)
Create a chain operation to handle dependencies.
Declaration
public AsyncOperationHandle<TObject> CreateChainOperation<TObject>(AsyncOperationHandle dependentOp, Func<AsyncOperationHandle, AsyncOperationHandle<TObject>> callback, bool releaseDependenciesOnFailure = true)
Parameters
| Type | Name | Description |
|---|---|---|
| AsyncOperationHandle | dependentOp | The dependency operation. |
| Func<AsyncOperationHandle, AsyncOperationHandle<TObject>> | callback | The callback method that will create the dependent operation from the dependency operation. |
| Boolean | releaseDependenciesOnFailure | Whether to release dependencies if the created operation has failed. |
Returns
| Type | Description |
|---|---|
| AsyncOperationHandle<TObject> | The operation handle. |
Type Parameters
| Name | Description |
|---|---|
| TObject | The type of operation handle to return. |
CreateChainOperation<TObject, TObjectDependency>(AsyncOperationHandle<TObjectDependency>, Func<AsyncOperationHandle<TObjectDependency>, AsyncOperationHandle<TObject>>)
Create a chain operation to handle dependencies.
Declaration
public AsyncOperationHandle<TObject> CreateChainOperation<TObject, TObjectDependency>(AsyncOperationHandle<TObjectDependency> dependentOp, Func<AsyncOperationHandle<TObjectDependency>, AsyncOperationHandle<TObject>> callback)
Parameters
| Type | Name | Description |
|---|---|---|
| AsyncOperationHandle<TObjectDependency> | dependentOp | The dependency operation. |
| Func<AsyncOperationHandle<TObjectDependency>, AsyncOperationHandle<TObject>> | callback | The callback method that will create the dependent operation from the dependency operation. |
Returns
| Type | Description |
|---|---|
| AsyncOperationHandle<TObject> | The operation handle. |
Type Parameters
| Name | Description |
|---|---|
| TObject | The type of operation handle to return. |
| TObjectDependency | The type of the dependency operation. |
CreateChainOperation<TObject, TObjectDependency>(AsyncOperationHandle<TObjectDependency>, Func<AsyncOperationHandle<TObjectDependency>, AsyncOperationHandle<TObject>>, Boolean)
Create a chain operation to handle dependencies.
Declaration
public AsyncOperationHandle<TObject> CreateChainOperation<TObject, TObjectDependency>(AsyncOperationHandle<TObjectDependency> dependentOp, Func<AsyncOperationHandle<TObjectDependency>, AsyncOperationHandle<TObject>> callback, bool releaseDependenciesOnFailure = true)
Parameters
| Type | Name | Description |
|---|---|---|
| AsyncOperationHandle<TObjectDependency> | dependentOp | The dependency operation. |
| Func<AsyncOperationHandle<TObjectDependency>, AsyncOperationHandle<TObject>> | callback | The callback method that will create the dependent operation from the dependency operation. |
| Boolean | releaseDependenciesOnFailure | Whether to release dependencies if the created operation has failed. |
Returns
| Type | Description |
|---|---|
| AsyncOperationHandle<TObject> | The operation handle. |
Type Parameters
| Name | Description |
|---|---|
| TObject | The type of operation handle to return. |
| TObjectDependency | The type of the dependency operation. |
CreateCompletedOperation<TObject>(TObject, String)
Creates an operation that has already completed with a specified result and error message./>.
Declaration
public AsyncOperationHandle<TObject> CreateCompletedOperation<TObject>(TObject result, string errorMsg)
Parameters
| Type | Name | Description |
|---|---|---|
| TObject | result | The result that the operation will provide. |
| String | errorMsg | The error message if the operation should be in the failed state. Otherwise null or empty string. |
Returns
| Type | Description |
|---|---|
| AsyncOperationHandle<TObject> | The operation handle used for the completed operation. |
Type Parameters
| Name | Description |
|---|---|
| TObject | Object type. |
CreateCompletedOperationWithException<TObject>(TObject, Exception)
Creates an operation that has already completed with a specified result and error message./>.
Declaration
public AsyncOperationHandle<TObject> CreateCompletedOperationWithException<TObject>(TObject result, Exception exception)
Parameters
| Type | Name | Description |
|---|---|---|
| TObject | result | The result that the operation will provide. |
| Exception | exception | The exception with an error message if the operation should be in the failed state. Otherwise null. |
Returns
| Type | Description |
|---|---|
| AsyncOperationHandle<TObject> | The operation handle used for the completed operation. |
Type Parameters
| Name | Description |
|---|---|
| TObject | Object type. |
CreateGenericGroupOperation(List<AsyncOperationHandle>, Boolean)
Create a group operation for a set of AsyncOperationHandles
Declaration
public AsyncOperationHandle<IList<AsyncOperationHandle>> CreateGenericGroupOperation(List<AsyncOperationHandle> operations, bool releasedCachedOpOnComplete = false)
Parameters
| Type | Name | Description |
|---|---|---|
| List<AsyncOperationHandle> | operations | The list of operations that need to complete. |
| Boolean | releasedCachedOpOnComplete | Determine if the cached operation should be released or not. |
Returns
| Type | Description |
|---|---|
| AsyncOperationHandle<IList<AsyncOperationHandle>> | The operation for the entire group |
CreateGroupOperation<T>(IList<IResourceLocation>)
Create a group operation for a set of locations.
Declaration
public AsyncOperationHandle<IList<AsyncOperationHandle>> CreateGroupOperation<T>(IList<IResourceLocation> locations)
Parameters
| Type | Name | Description |
|---|---|---|
| IList<IResourceLocation> | locations | The list of locations to load. |
Returns
| Type | Description |
|---|---|
| AsyncOperationHandle<IList<AsyncOperationHandle>> | The operation for the entire group. |
Type Parameters
| Name | Description |
|---|---|
| T | The expected object type for the operations. |
Dispose()
Disposes internal resources used by the resource manager
Declaration
public void Dispose()
GetResourceProvider(Type, IResourceLocation)
Gets the appropriate IResourceProvider for the given location and type.
Declaration
public IResourceProvider GetResourceProvider(Type t, IResourceLocation location)
Parameters
| Type | Name | Description |
|---|---|---|
| Type | t | The desired object type to be loaded from the provider. |
| IResourceLocation | location | The resource location. |
Returns
| Type | Description |
|---|---|
| IResourceProvider | The resource provider. Or null if an appropriate provider cannot be found |
ProvideInstance(IInstanceProvider, IResourceLocation, InstantiationParameters)
Asynchronously instantiate a prefab (GameObject) at the specified location.
Declaration
public AsyncOperationHandle<GameObject> ProvideInstance(IInstanceProvider provider, IResourceLocation location, InstantiationParameters instantiateParameters)
Parameters
| Type | Name | Description |
|---|---|---|
| IInstanceProvider | provider | An implementation of IInstanceProvider that will be used to instantiate and destroy the GameObject. |
| IResourceLocation | location | Location of the prefab. |
| InstantiationParameters | instantiateParameters | A struct containing the parameters to pass the the Instantiation call. |
Returns
| Type | Description |
|---|---|
| AsyncOperationHandle<GameObject> | Async operation that will complete when the prefab is instantiated. |
ProvideResource<TObject>(IResourceLocation)
Load the TObject at the specified location.
Declaration
public AsyncOperationHandle<TObject> ProvideResource<TObject>(IResourceLocation location)
Parameters
| Type | Name | Description |
|---|---|---|
| IResourceLocation | location | Location to load. |
Returns
| Type | Description |
|---|---|
| AsyncOperationHandle<TObject> | An async operation. |
Type Parameters
| Name | Description |
|---|---|
| TObject | Object type to load. |
ProvideResources<TObject>(IList<IResourceLocation>, Action<TObject>)
Asynchronously load all objects in the given collection of locations.
If any matching location fails, all loads and dependencies will be released. The returned .Result will be null, and .Status will be Failed.
Declaration
public AsyncOperationHandle<IList<TObject>> ProvideResources<TObject>(IList<IResourceLocation> locations, Action<TObject> callback = null)
Parameters
| Type | Name | Description |
|---|---|---|
| IList<IResourceLocation> | locations | locations to load. |
| Action<TObject> | callback | This callback will be invoked once for each object that is loaded. |
Returns
| Type | Description |
|---|---|
| AsyncOperationHandle<IList<TObject>> | An async operation that will complete when all individual async load operations are complete. |
Type Parameters
| Name | Description |
|---|---|
| TObject | Object type to load. |
ProvideResources<TObject>(IList<IResourceLocation>, Boolean, Action<TObject>)
Asynchronously load all objects in the given collection of locations.
Declaration
public AsyncOperationHandle<IList<TObject>> ProvideResources<TObject>(IList<IResourceLocation> locations, bool releaseDependenciesOnFailure, Action<TObject> callback = null)
Parameters
| Type | Name | Description |
|---|---|---|
| IList<IResourceLocation> | locations | locations to load. |
| Boolean | releaseDependenciesOnFailure | If all matching locations succeed, this parameter is ignored. When true, if any matching location fails, all loads and dependencies will be released. The returned .Result will be null, and .Status will be Failed. When false, if any matching location fails, the returned .Result will be an IList of size equal to the number of locations attempted. Any failed location will correlate to a null in the IList, while successful loads will correlate to a TObject in the list. The .Status will still be Failed. When true, op does not need to be released if anything fails, when false, it must always be released. |
| Action<TObject> | callback | This callback will be invoked once for each object that is loaded. |
Returns
| Type | Description |
|---|---|
| AsyncOperationHandle<IList<TObject>> | An async operation that will complete when all individual async load operations are complete. |
Type Parameters
| Name | Description |
|---|---|
| TObject | Object type to load. |
ProvideScene(ISceneProvider, IResourceLocation, LoadSceneMode, Boolean, Int32)
Load a scene at a specificed resource location.
Declaration
public AsyncOperationHandle<SceneInstance> ProvideScene(ISceneProvider sceneProvider, IResourceLocation location, LoadSceneMode loadMode, bool activateOnLoad, int priority)
Parameters
| Type | Name | Description |
|---|---|---|
| ISceneProvider | sceneProvider | The scene provider instance. |
| IResourceLocation | location | The location of the scene. |
| LoadSceneMode | loadMode | The load mode for the scene. |
| Boolean | activateOnLoad | If false, the scene will be loaded in the background and not activated when complete. |
| Int32 | priority | The priority for the load operation. |
Returns
| Type | Description |
|---|---|
| AsyncOperationHandle<SceneInstance> | Async operation handle that will complete when the scene is loaded. If activateOnLoad is false, then Activate() will need to be called on the SceneInstance returned. |
RegisterDiagnosticCallback(Action<AsyncOperationHandle, ResourceManager.DiagnosticEventType, Int32, Object>)
Register a handler for diagnostic events.
Declaration
public void RegisterDiagnosticCallback(Action<AsyncOperationHandle, ResourceManager.DiagnosticEventType, int, object> func)
Parameters
| Type | Name | Description |
|---|---|---|
| Action<AsyncOperationHandle, ResourceManager.DiagnosticEventType, Int32, Object> | func | The event handler function. |
RegisterDiagnosticCallback(Action<ResourceManager.DiagnosticEventContext>)
Register a handler for diagnostic events.
Declaration
public void RegisterDiagnosticCallback(Action<ResourceManager.DiagnosticEventContext> func)
Parameters
| Type | Name | Description |
|---|---|---|
| Action<ResourceManager.DiagnosticEventContext> | func | The event handler function. |
Release(AsyncOperationHandle)
Release the operation associated with the specified handle
Declaration
public void Release(AsyncOperationHandle handle)
Parameters
| Type | Name | Description |
|---|---|---|
| AsyncOperationHandle | handle | The handle to release. |
ReleaseScene(ISceneProvider, AsyncOperationHandle<SceneInstance>)
Release a scene.
Declaration
public AsyncOperationHandle<SceneInstance> ReleaseScene(ISceneProvider sceneProvider, AsyncOperationHandle<SceneInstance> sceneLoadHandle)
Parameters
| Type | Name | Description |
|---|---|---|
| ISceneProvider | sceneProvider | The scene provider. |
| AsyncOperationHandle<SceneInstance> | sceneLoadHandle | The operation handle used to load the scene. |
Returns
| Type | Description |
|---|---|
| AsyncOperationHandle<SceneInstance> | An operation handle for the unload. |
RemoveUpdateReciever(IUpdateReceiver)
Remove update receiver.
Declaration
public void RemoveUpdateReciever(IUpdateReceiver receiver)
Parameters
| Type | Name | Description |
|---|---|---|
| IUpdateReceiver | receiver | The object to remove. |
StartOperation<TObject>(AsyncOperationBase<TObject>, AsyncOperationHandle)
Registers an operation with the ResourceManager. The operation will be executed when the dependency completes.
This should only be used when creating custom operations.
Declaration
public AsyncOperationHandle<TObject> StartOperation<TObject>(AsyncOperationBase<TObject> operation, AsyncOperationHandle dependency)
Parameters
| Type | Name | Description |
|---|---|---|
| AsyncOperationBase<TObject> | operation | The custom AsyncOperationBase object |
| AsyncOperationHandle | dependency | Execution of the operation will not occur until this handle completes. A default handle can be passed if no dependency is required. |
Returns
| Type | Description |
|---|---|
| AsyncOperationHandle<TObject> | The AsyncOperationHandle used to access the result and status of the operation. |
Type Parameters
| Name | Description |
|---|---|
| TObject | Object type associated with this operation. |
TransformInternalId(IResourceLocation)
Checks for an internal id transform function and uses it to modify the internal id value.
Declaration
public string TransformInternalId(IResourceLocation location)
Parameters
| Type | Name | Description |
|---|---|---|
| IResourceLocation | location | The location to transform the internal id of. |
Returns
| Type | Description |
|---|---|
| String | If a transform func is set, use it to pull the local id. otheriwse the InternalId property of the location is used. |
UnregisterDiagnosticCallback(Action<ResourceManager.DiagnosticEventContext>)
Unregister a handler for diagnostic events.
Declaration
public void UnregisterDiagnosticCallback(Action<ResourceManager.DiagnosticEventContext> func)
Parameters
| Type | Name | Description |
|---|---|---|
| Action<ResourceManager.DiagnosticEventContext> | func | The event handler function. |