Class ResourceCache<TAsset>
Loading and cache specific asset as a group and release them by control version
public class ResourceCache<TAsset> : IDisposable, IReadOnlyDictionary<string, TAsset>, IReadOnlyCollection<KeyValuePair<string, TAsset>>, IEnumerable<KeyValuePair<string, TAsset>>, IEnumerable where TAsset : Object
Type Parameters
TAsset
- Inheritance
-
ResourceCache<TAsset>
- Implements
-
IReadOnlyDictionary<string, TAsset>
- Derived
- Inherited Members
- Extension Methods
Constructors
ResourceCache()
public ResourceCache()
Properties
AddressSafeCheck
Validate asset location before loading, throw InvalidResourceRequestException if not exist
public bool AddressSafeCheck { get; set; }
Property Value
Count
public int Count { get; }
Property Value
IsLoading
Flags when any asset is in loading
public bool IsLoading { get; }
Property Value
this[string]
public TAsset this[string key] { get; }
Parameters
keystring
Property Value
- TAsset
Keys
public IEnumerable<string> Keys { get; }
Property Value
Values
public IEnumerable<TAsset> Values { get; }
Property Value
- IEnumerable<TAsset>
Version
Current cache version
public int Version { get; }
Property Value
Methods
ContainsKey(string)
public bool ContainsKey(string key)
Parameters
keystring
Returns
Dispose()
Implementation of IDisposable, release all handles in cache.
public virtual void Dispose()
GetCacheKeys()
Get cache addresses
public IEnumerable<string> GetCacheKeys()
Returns
GetEnumerator()
public IEnumerator<KeyValuePair<string, TAsset>> GetEnumerator()
Returns
- IEnumerator<KeyValuePair<string, TAsset>>
LoadAsset(string)
Load and cache asset in sync way which will block game, not recommend
public TAsset LoadAsset(string address)
Parameters
addressstring
Returns
- TAsset
LoadAssetAsync(string)
Load and cache asset async
public UniTask<TAsset> LoadAssetAsync(string address)
Parameters
addressstring
Returns
- UniTask<TAsset>
ReleaseAssetsAndUpdateVersion()
Release assets with last version and update version
public void ReleaseAssetsAndUpdateVersion()
ReleaseAssetsWithVersion(int)
Release all assets with target version
public void ReleaseAssetsWithVersion(int version)
Parameters
versionint
TryGetValue(string, out TAsset)
public bool TryGetValue(string key, out TAsset value)
Parameters
keystringvalueTAsset
Returns
UpdateVersion()
Update version
public int UpdateVersion()