Class CachedProvider
Provider that can wrap other IResourceProviders and add caching and reference counting of objects.
Inheritance
Namespace: UnityEngine.ResourceManagement.ResourceProviders
Syntax
public class CachedProvider : IResourceProvider, IInitializableObject, IUpdateReceiver
Constructors
CachedProvider()
Construct a new CachedProvider object. Initialize should be called after construction.
Declaration
public CachedProvider()
CachedProvider(IResourceProvider, String, Int32, Single)
Construct a new CachedProvider object.
Declaration
public CachedProvider(IResourceProvider provider, string providerId, int maxCacheItemCount = 0, float maxCacheItemAge = 0F)
Parameters
Type | Name | Description |
---|---|---|
IResourceProvider | provider | The internal provider that will handle the loading and releasing of the objects. |
System.String | providerId | |
System.Int32 | maxCacheItemCount | How many items to keep in the cache. If set to 0, items are not cached. |
System.Single | maxCacheItemAge | How long to keep items in the cache. If set to 0, cached items are kept indefinitely. |
Properties
BehaviourFlags
Declaration
public ProviderBehaviourFlags BehaviourFlags { get; }
Property Value
Type | Description |
---|---|
ProviderBehaviourFlags |
Implements
ProviderId
Unique identifier for this provider, used by Resource Locations to find a suitable Provider
Declaration
public string ProviderId { get; }
Property Value
Type | Description |
---|---|
System.String | The provider identifier. |
Implements
Methods
CanProvide<TObject>(IResourceLocation)
Evaluate whether or not the provider can load the given location.
Declaration
public bool CanProvide<TObject>(IResourceLocation location)
where TObject : class
Parameters
Type | Name | Description |
---|---|---|
IResourceLocation | location | Location to evaluate. |
Returns
Type | Description |
---|---|
System.Boolean |
|
Type Parameters
Name | Description |
---|---|
TObject | The object type for the given location. |
Implements
Initialize(String, String)
Initialize this instance.
Declaration
public bool Initialize(string id, string data)
Parameters
Type | Name | Description |
---|---|---|
System.String | id | The provider id. |
System.String | data | Serialized data. This can be generated by calling CreateInitializationData. |
Returns
Type | Description |
---|---|
System.Boolean |
Implements
Provide<TObject>(IResourceLocation, IList<Object>)
Provide the requested object. The cache will be checked first for existing objects. If not found, the internal IResourceProvider will be used to provide the object. The reference count for the asset will be incremented.
Declaration
public IAsyncOperation<TObject> Provide<TObject>(IResourceLocation location, IList<object> deps)
where TObject : class
Parameters
Type | Name | Description |
---|---|---|
IResourceLocation | location | |
System.Collections.Generic.IList<System.Object> | deps |
Returns
Type | Description |
---|---|
IAsyncOperation<TObject> |
Type Parameters
Name | Description |
---|---|
TObject |
Implements
Release(IResourceLocation, Object)
Releasing an object to a CachedProvider will decrease it reference count, which may result in the object getting actually released. Released objects are added to an in memory cache.
Declaration
public bool Release(IResourceLocation location, object asset)
Parameters
Type | Name | Description |
---|---|---|
IResourceLocation | location | The location of the object. |
System.Object | asset | The object to release. |
Returns
Type | Description |
---|---|
System.Boolean | True if the reference count reaches 0 and the asset is released. |
Implements
ToString()
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
System.String |
Overrides
Explicit Interface Implementations
IUpdateReceiver.NeedsUpdate
Declaration
bool IUpdateReceiver.NeedsUpdate { get; }
Returns
Type | Description |
---|---|
System.Boolean |
Implements
IUpdateReceiver.Update(Single)
Declaration
void IUpdateReceiver.Update(float deltaTime)
Parameters
Type | Name | Description |
---|---|---|
System.Single | deltaTime |