mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-07 16:45:10 +00:00
资源模块优化、UI模块优化,增加接口参数是否使用缓存资源操作句柄。
资源模块优化、UI模块优化,增加接口参数是否使用缓存资源操作句柄、如果需要则不会淘汰缓存队列中的资源清单。
This commit is contained in:
@@ -165,9 +165,10 @@ namespace TEngine
|
||||
/// </summary>
|
||||
/// <param name="location">资源的定位地址。</param>
|
||||
/// <param name="needInstance">是否需要实例化。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <typeparam name="T">要加载资源的类型。</typeparam>
|
||||
/// <returns>资源实例。</returns>
|
||||
T LoadAsset<T>(string location, bool needInstance) where T : Object;
|
||||
T LoadAsset<T>(string location, bool needInstance, bool needCache = false) where T : Object;
|
||||
|
||||
/// <summary>
|
||||
/// 同步加载资源。
|
||||
@@ -175,18 +176,20 @@ namespace TEngine
|
||||
/// <param name="location">资源的定位地址。</param>
|
||||
/// <param name="parent">父节点位置。</param>
|
||||
/// <param name="needInstance">是否需要实例化。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <typeparam name="T">要加载资源的类型。</typeparam>
|
||||
/// <returns>资源实例。</returns>
|
||||
T LoadAsset<T>(string location, Transform parent, bool needInstance) where T : Object;
|
||||
T LoadAsset<T>(string location, Transform parent, bool needInstance, bool needCache = false) where T : Object;
|
||||
|
||||
/// <summary>
|
||||
/// 同步加载资源。
|
||||
/// </summary>
|
||||
/// <param name="handle">资源操作句柄。</param>
|
||||
/// <param name="location">资源的定位地址。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <typeparam name="T">要加载资源的类型。</typeparam>
|
||||
/// <returns>资源实例。</returns>
|
||||
T LoadAsset<T>(string location, out AssetOperationHandle handle) where T : Object;
|
||||
T LoadAsset<T>(string location, out AssetOperationHandle handle, bool needCache = false) where T : Object;
|
||||
|
||||
/// <summary>
|
||||
/// 同步加载资源。
|
||||
@@ -194,25 +197,28 @@ namespace TEngine
|
||||
/// <param name="location">资源的定位地址。</param>
|
||||
/// <param name="handle">资源操作句柄。</param>
|
||||
/// <param name="parent">父节点位置。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <typeparam name="T">要加载资源的类型。</typeparam>
|
||||
/// <returns>资源实例。</returns>
|
||||
T LoadAsset<T>(string location, Transform parent, out AssetOperationHandle handle) where T : Object;
|
||||
T LoadAsset<T>(string location, Transform parent, out AssetOperationHandle handle, bool needCache = false) where T : Object;
|
||||
|
||||
/// <summary>
|
||||
/// 同步加载资源并获取句柄。
|
||||
/// </summary>
|
||||
/// <param name="location">资源的定位地址。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <typeparam name="T">要加载资源的类型。</typeparam>
|
||||
/// <returns>同步加载资源句柄。</returns>
|
||||
AssetOperationHandle LoadAssetGetOperation<T>(string location) where T : Object;
|
||||
AssetOperationHandle LoadAssetGetOperation<T>(string location, bool needCache = false) where T : Object;
|
||||
|
||||
/// <summary>
|
||||
/// 异步加载资源并获取句柄。
|
||||
/// </summary>
|
||||
/// <param name="location">资源的定位地址。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <typeparam name="T">要加载资源的类型。</typeparam>
|
||||
/// <returns>异步加载资源句柄。</returns>
|
||||
AssetOperationHandle LoadAssetAsyncHandle<T>(string location) where T : Object;
|
||||
AssetOperationHandle LoadAssetAsyncHandle<T>(string location, bool needCache = false) where T : Object;
|
||||
|
||||
/// <summary>
|
||||
/// 同步加载子资源对象。
|
||||
@@ -269,17 +275,19 @@ namespace TEngine
|
||||
/// <param name="location">资源定位地址。</param>
|
||||
/// <param name="cancellationToken">取消操作Token。</param>
|
||||
/// <param name="needInstance">是否需要实例化。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <typeparam name="T">要加载资源的类型。</typeparam>
|
||||
/// <returns>异步资源实例。</returns>
|
||||
UniTask<T> LoadAssetAsync<T>(string location, CancellationToken cancellationToken = default, bool needInstance = true) where T : Object;
|
||||
UniTask<T> LoadAssetAsync<T>(string location, CancellationToken cancellationToken = default, bool needInstance = true, bool needCache = false) where T : Object;
|
||||
|
||||
/// <summary>
|
||||
/// 异步加载游戏物体。
|
||||
/// </summary>
|
||||
/// <param name="location">资源定位地址。</param>
|
||||
/// <param name="cancellationToken">取消操作Token。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <returns>异步游戏物体实例。</returns>
|
||||
UniTask<GameObject> LoadGameObjectAsync(string location, CancellationToken cancellationToken = default);
|
||||
UniTask<GameObject> LoadGameObjectAsync(string location, CancellationToken cancellationToken = default, bool needCache = false);
|
||||
|
||||
/// <summary>
|
||||
/// 异步加载游戏物体。
|
||||
@@ -287,8 +295,9 @@ namespace TEngine
|
||||
/// <param name="location">资源定位地址。</param>
|
||||
/// <param name="parent">父节点位置。</param>
|
||||
/// <param name="cancellationToken">取消操作Token。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <returns>异步游戏物体实例。</returns>
|
||||
UniTask<GameObject> LoadGameObjectAsync(string location, Transform parent, CancellationToken cancellationToken = default);
|
||||
UniTask<GameObject> LoadGameObjectAsync(string location, Transform parent, CancellationToken cancellationToken = default, bool needCache = false);
|
||||
|
||||
/// <summary>
|
||||
/// 异步加载原生文件。
|
||||
|
@@ -204,10 +204,15 @@ namespace TEngine
|
||||
/// 从缓存中获取同步资源句柄。
|
||||
/// </summary>
|
||||
/// <param name="location">资源定位地址。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <typeparam name="T">资源类型。</typeparam>
|
||||
/// <returns>资源句柄。</returns>
|
||||
private AssetOperationHandle GetHandleSync<T>(string location) where T : Object
|
||||
private AssetOperationHandle GetHandleSync<T>(string location, bool needCache = false) where T : Object
|
||||
{
|
||||
if (!needCache)
|
||||
{
|
||||
return YooAssets.LoadAssetSync<T>(location);
|
||||
}
|
||||
AssetOperationHandle handle = null;
|
||||
// 尝试从从ARC缓存表取出对象。
|
||||
handle = _arcCacheTable.GetCache(location);
|
||||
@@ -226,10 +231,15 @@ namespace TEngine
|
||||
/// 从缓存中获取异步资源句柄。
|
||||
/// </summary>
|
||||
/// <param name="location">资源定位地址。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <typeparam name="T">资源类型。</typeparam>
|
||||
/// <returns>资源句柄。</returns>
|
||||
private AssetOperationHandle GetHandleAsync<T>(string location) where T : Object
|
||||
private AssetOperationHandle GetHandleAsync<T>(string location, bool needCache = false) where T : Object
|
||||
{
|
||||
if (!needCache)
|
||||
{
|
||||
return YooAssets.LoadAssetAsync<T>(location);
|
||||
}
|
||||
AssetOperationHandle handle = null;
|
||||
// 尝试从从ARC缓存表取出对象。
|
||||
handle = _arcCacheTable.GetCache(location);
|
||||
@@ -499,9 +509,10 @@ namespace TEngine
|
||||
/// </summary>
|
||||
/// <param name="location">资源的定位地址。</param>
|
||||
/// <param name="needInstance">是否需要实例化。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <typeparam name="T">要加载资源的类型。</typeparam>
|
||||
/// <returns>资源实例。</returns>
|
||||
public T LoadAsset<T>(string location, bool needInstance = true) where T : Object
|
||||
public T LoadAsset<T>(string location, bool needInstance = true, bool needCache = false) where T : Object
|
||||
{
|
||||
if (string.IsNullOrEmpty(location))
|
||||
{
|
||||
@@ -509,23 +520,27 @@ namespace TEngine
|
||||
return default;
|
||||
}
|
||||
|
||||
AssetOperationHandle handle = GetHandleSync<T>(location);
|
||||
AssetOperationHandle handle = GetHandleSync<T>(location, needCache);
|
||||
|
||||
if (typeof(T) == typeof(GameObject))
|
||||
{
|
||||
if (needInstance)
|
||||
{
|
||||
GameObject ret = handle.InstantiateSync();
|
||||
return ret as T;
|
||||
GameObject gameObject = handle.InstantiateSync();
|
||||
if (!needCache)
|
||||
{
|
||||
AssetReference.BindAssetReference(gameObject, handle, location);
|
||||
}
|
||||
return gameObject as T;
|
||||
}
|
||||
}
|
||||
|
||||
return handle.AssetObject as T;
|
||||
}
|
||||
else
|
||||
{
|
||||
T ret = handle.AssetObject as T;
|
||||
return ret;
|
||||
if (!needCache)
|
||||
{
|
||||
handle.Dispose();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -534,9 +549,10 @@ namespace TEngine
|
||||
/// <param name="location">资源的定位地址。</param>
|
||||
/// <param name="parent">父节点位置。</param>
|
||||
/// <param name="needInstance">是否需要实例化。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <typeparam name="T">要加载资源的类型。</typeparam>
|
||||
/// <returns>资源实例。</returns>
|
||||
public T LoadAsset<T>(string location, Transform parent, bool needInstance = true) where T : Object
|
||||
public T LoadAsset<T>(string location, Transform parent, bool needInstance = true, bool needCache = false) where T : Object
|
||||
{
|
||||
if (string.IsNullOrEmpty(location))
|
||||
{
|
||||
@@ -544,23 +560,27 @@ namespace TEngine
|
||||
return default;
|
||||
}
|
||||
|
||||
AssetOperationHandle handle = GetHandleSync<T>(location);
|
||||
AssetOperationHandle handle = GetHandleSync<T>(location, needCache);
|
||||
|
||||
if (typeof(T) == typeof(GameObject))
|
||||
{
|
||||
if (needInstance)
|
||||
{
|
||||
GameObject ret = handle.InstantiateSync(parent);
|
||||
return ret as T;
|
||||
GameObject gameObject = handle.InstantiateSync(parent);
|
||||
if (!needCache)
|
||||
{
|
||||
AssetReference.BindAssetReference(gameObject, handle, location);
|
||||
}
|
||||
return gameObject as T;
|
||||
}
|
||||
}
|
||||
|
||||
return handle.AssetObject as T;
|
||||
}
|
||||
else
|
||||
{
|
||||
T ret = handle.AssetObject as T;
|
||||
return ret;
|
||||
if (!needCache)
|
||||
{
|
||||
handle.Dispose();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -568,11 +588,12 @@ namespace TEngine
|
||||
/// </summary>
|
||||
/// <param name="handle">资源操作句柄。</param>
|
||||
/// <param name="location">资源的定位地址。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <typeparam name="T">要加载资源的类型。</typeparam>
|
||||
/// <returns>资源实例。</returns>
|
||||
public T LoadAsset<T>(string location, out AssetOperationHandle handle) where T : Object
|
||||
public T LoadAsset<T>(string location, out AssetOperationHandle handle, bool needCache = false) where T : Object
|
||||
{
|
||||
handle = GetHandleSync<T>(location);
|
||||
handle = GetHandleSync<T>(location, needCache);
|
||||
if (string.IsNullOrEmpty(location))
|
||||
{
|
||||
Log.Error("Asset name is invalid.");
|
||||
@@ -581,13 +602,20 @@ namespace TEngine
|
||||
|
||||
if (typeof(T) == typeof(GameObject))
|
||||
{
|
||||
GameObject ret = handle.InstantiateSync();
|
||||
return ret as T;
|
||||
}
|
||||
else
|
||||
GameObject gameObject = handle.InstantiateSync();
|
||||
if (!needCache)
|
||||
{
|
||||
return handle.AssetObject as T;
|
||||
AssetReference.BindAssetReference(gameObject, handle, location);
|
||||
}
|
||||
return gameObject as T;
|
||||
}
|
||||
|
||||
T ret = handle.AssetObject as T;
|
||||
if (!needCache)
|
||||
{
|
||||
handle.Dispose();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -595,12 +623,13 @@ namespace TEngine
|
||||
/// </summary>
|
||||
/// <param name="location">资源的定位地址。</param>
|
||||
/// <param name="handle">资源操作句柄。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <param name="parent">父节点位置。</param>
|
||||
/// <typeparam name="T">要加载资源的类型。</typeparam>
|
||||
/// <returns>资源实例。</returns>
|
||||
public T LoadAsset<T>(string location, Transform parent, out AssetOperationHandle handle) where T : Object
|
||||
public T LoadAsset<T>(string location, Transform parent, out AssetOperationHandle handle, bool needCache = false) where T : Object
|
||||
{
|
||||
handle = GetHandleSync<T>(location);
|
||||
handle = GetHandleSync<T>(location, needCache);
|
||||
|
||||
if (string.IsNullOrEmpty(location))
|
||||
{
|
||||
@@ -610,35 +639,44 @@ namespace TEngine
|
||||
|
||||
if (typeof(T) == typeof(GameObject))
|
||||
{
|
||||
GameObject ret = handle.InstantiateSync(parent);
|
||||
return ret as T;
|
||||
}
|
||||
else
|
||||
GameObject gameObject = handle.InstantiateSync(parent);
|
||||
if (!needCache)
|
||||
{
|
||||
return handle.AssetObject as T;
|
||||
AssetReference.BindAssetReference(gameObject, handle, location);
|
||||
}
|
||||
return gameObject as T;
|
||||
}
|
||||
|
||||
T ret = handle.AssetObject as T;
|
||||
if (!needCache)
|
||||
{
|
||||
handle.Dispose();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 同步加载资源并获取句柄。
|
||||
/// </summary>
|
||||
/// <param name="location">资源的定位地址。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <typeparam name="T">要加载资源的类型。</typeparam>
|
||||
/// <returns>同步加载资源句柄。</returns>
|
||||
public AssetOperationHandle LoadAssetGetOperation<T>(string location) where T : Object
|
||||
public AssetOperationHandle LoadAssetGetOperation<T>(string location, bool needCache = false) where T : Object
|
||||
{
|
||||
return GetHandleSync<T>(location);
|
||||
return GetHandleSync<T>(location, needCache);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步加载资源并获取句柄。
|
||||
/// </summary>
|
||||
/// <param name="location">资源的定位地址。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <typeparam name="T">要加载资源的类型。</typeparam>
|
||||
/// <returns>异步加载资源句柄。</returns>
|
||||
public AssetOperationHandle LoadAssetAsyncHandle<T>(string location) where T : Object
|
||||
public AssetOperationHandle LoadAssetAsyncHandle<T>(string location, bool needCache = false) where T : Object
|
||||
{
|
||||
return GetHandleAsync<T>(location);
|
||||
return GetHandleAsync<T>(location, needCache);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -721,10 +759,11 @@ namespace TEngine
|
||||
/// <param name="location">要加载的实例名称。</param>
|
||||
/// <param name="cancellationToken">取消操作Token。</param>
|
||||
/// <param name="needInstance">是否需要实例化。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <returns>资源实实例。</returns>
|
||||
public async UniTask<T> LoadAssetAsync<T>(string location, CancellationToken cancellationToken = default, bool needInstance = true) where T : Object
|
||||
public async UniTask<T> LoadAssetAsync<T>(string location, CancellationToken cancellationToken = default, bool needInstance = true, bool needCache = false) where T : Object
|
||||
{
|
||||
AssetOperationHandle handle = LoadAssetAsyncHandle<T>(location);
|
||||
AssetOperationHandle handle = LoadAssetAsyncHandle<T>(location, needCache);
|
||||
|
||||
bool cancelOrFailed = await handle.ToUniTask().AttachExternalCancellation(cancellationToken).SuppressCancellationThrow();
|
||||
|
||||
@@ -737,16 +776,21 @@ namespace TEngine
|
||||
{
|
||||
if (needInstance)
|
||||
{
|
||||
GameObject ret = handle.InstantiateSync();
|
||||
return ret as T;
|
||||
GameObject gameObject = handle.InstantiateSync();
|
||||
if (!needCache)
|
||||
{
|
||||
AssetReference.BindAssetReference(gameObject, handle, location);
|
||||
}
|
||||
return gameObject as T;
|
||||
}
|
||||
}
|
||||
|
||||
return handle.AssetObject as T;
|
||||
}
|
||||
else
|
||||
T ret = handle.AssetObject as T;
|
||||
if (!needCache)
|
||||
{
|
||||
return handle.AssetObject as T;
|
||||
handle.Dispose();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -754,10 +798,11 @@ namespace TEngine
|
||||
/// </summary>
|
||||
/// <param name="location">要加载的游戏物体名称。</param>
|
||||
/// <param name="cancellationToken">取消操作Token。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <returns>异步游戏物体实例。</returns>
|
||||
public async UniTask<GameObject> LoadGameObjectAsync(string location, CancellationToken cancellationToken = default)
|
||||
public async UniTask<GameObject> LoadGameObjectAsync(string location, CancellationToken cancellationToken = default, bool needCache = false)
|
||||
{
|
||||
AssetOperationHandle handle = LoadAssetAsyncHandle<GameObject>(location);
|
||||
AssetOperationHandle handle = LoadAssetAsyncHandle<GameObject>(location, needCache);
|
||||
|
||||
bool cancelOrFailed = await handle.ToUniTask().AttachExternalCancellation(cancellationToken).SuppressCancellationThrow();
|
||||
|
||||
@@ -766,9 +811,12 @@ namespace TEngine
|
||||
return null;
|
||||
}
|
||||
|
||||
GameObject ret = handle.InstantiateSync();
|
||||
|
||||
return ret;
|
||||
GameObject gameObject = handle.InstantiateSync();
|
||||
if (!needCache)
|
||||
{
|
||||
AssetReference.BindAssetReference(gameObject, handle, location);
|
||||
}
|
||||
return gameObject;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -777,10 +825,11 @@ namespace TEngine
|
||||
/// <param name="location">资源定位地址。</param>
|
||||
/// <param name="parent">父节点位置。</param>
|
||||
/// <param name="cancellationToken">取消操作Token。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <returns>异步游戏物体实例。</returns>
|
||||
public async UniTask<GameObject> LoadGameObjectAsync(string location, Transform parent, CancellationToken cancellationToken = default)
|
||||
public async UniTask<GameObject> LoadGameObjectAsync(string location, Transform parent, CancellationToken cancellationToken = default, bool needCache = false)
|
||||
{
|
||||
GameObject gameObject = await LoadGameObjectAsync(location, cancellationToken);
|
||||
GameObject gameObject = await LoadGameObjectAsync(location, cancellationToken, needCache);
|
||||
if (parent != null)
|
||||
{
|
||||
gameObject.transform.SetParent(parent);
|
||||
|
@@ -449,11 +449,12 @@ namespace TEngine
|
||||
/// </summary>
|
||||
/// <param name="location">资源的定位地址。</param>
|
||||
/// <param name="needInstance">是否需要实例化。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <typeparam name="T">要加载资源的类型。</typeparam>
|
||||
/// <returns>资源实例。</returns>
|
||||
public T LoadAsset<T>(string location, bool needInstance = true) where T : UnityEngine.Object
|
||||
public T LoadAsset<T>(string location, bool needInstance = true, bool needCache = false) where T : UnityEngine.Object
|
||||
{
|
||||
return m_ResourceManager.LoadAsset<T>(location, needInstance);
|
||||
return m_ResourceManager.LoadAsset<T>(location, needInstance, needCache);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -462,11 +463,12 @@ namespace TEngine
|
||||
/// <param name="location">资源的定位地址。</param>
|
||||
/// <param name="parent">父节点位置。</param>
|
||||
/// <param name="needInstance">是否需要实例化。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <typeparam name="T">要加载资源的类型。</typeparam>
|
||||
/// <returns>资源实例。</returns>
|
||||
public T LoadAsset<T>(string location, Transform parent, bool needInstance = true) where T : UnityEngine.Object
|
||||
public T LoadAsset<T>(string location, Transform parent, bool needInstance = true, bool needCache = false) where T : UnityEngine.Object
|
||||
{
|
||||
return m_ResourceManager.LoadAsset<T>(location, parent, needInstance);
|
||||
return m_ResourceManager.LoadAsset<T>(location, parent, needInstance, needCache);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -474,11 +476,12 @@ namespace TEngine
|
||||
/// </summary>
|
||||
/// <param name="handle">资源操作句柄。</param>
|
||||
/// <param name="location">资源的定位地址。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <typeparam name="T">要加载资源的类型。</typeparam>
|
||||
/// <returns>资源实例。</returns>
|
||||
public T LoadAsset<T>(string location, out AssetOperationHandle handle) where T : UnityEngine.Object
|
||||
public T LoadAsset<T>(string location, out AssetOperationHandle handle, bool needCache = false) where T : UnityEngine.Object
|
||||
{
|
||||
return m_ResourceManager.LoadAsset<T>(location, out handle);
|
||||
return m_ResourceManager.LoadAsset<T>(location, out handle, needCache);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -487,11 +490,12 @@ namespace TEngine
|
||||
/// <param name="location">资源的定位地址。</param>
|
||||
/// <param name="handle">资源操作句柄。</param>
|
||||
/// <param name="parent">父节点位置。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <typeparam name="T">要加载资源的类型。</typeparam>
|
||||
/// <returns>资源实例。</returns>
|
||||
public T LoadAsset<T>(string location, Transform parent, out AssetOperationHandle handle) where T : UnityEngine.Object
|
||||
public T LoadAsset<T>(string location, Transform parent, out AssetOperationHandle handle, bool needCache = false) where T : UnityEngine.Object
|
||||
{
|
||||
return m_ResourceManager.LoadAsset<T>(location, parent, out handle);
|
||||
return m_ResourceManager.LoadAsset<T>(location, parent, out handle, needCache);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -499,10 +503,11 @@ namespace TEngine
|
||||
/// </summary>
|
||||
/// <param name="location">资源的定位地址。</param>
|
||||
/// <param name="callback">回调函数。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <typeparam name="T">要加载资源的类型。</typeparam>
|
||||
public void LoadAssetAsync<T>(string location, Action<AssetOperationHandle> callback = null) where T : UnityEngine.Object
|
||||
public void LoadAssetAsync<T>(string location, Action<AssetOperationHandle> callback = null, bool needCache = false) where T : UnityEngine.Object
|
||||
{
|
||||
AssetOperationHandle handle = m_ResourceManager.LoadAssetAsyncHandle<T>(location);
|
||||
AssetOperationHandle handle = m_ResourceManager.LoadAssetAsyncHandle<T>(location, needCache);
|
||||
|
||||
handle.Completed += callback;
|
||||
}
|
||||
@@ -511,22 +516,24 @@ namespace TEngine
|
||||
/// 同步加载资源并获取句柄。
|
||||
/// </summary>
|
||||
/// <param name="location">资源的定位地址。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <typeparam name="T">要加载资源的类型。</typeparam>
|
||||
/// <returns>同步加载资源句柄。</returns>
|
||||
public AssetOperationHandle LoadAssetGetOperation<T>(string location) where T : UnityEngine.Object
|
||||
public AssetOperationHandle LoadAssetGetOperation<T>(string location, bool needCache = false) where T : UnityEngine.Object
|
||||
{
|
||||
return m_ResourceManager.LoadAssetGetOperation<T>(location);
|
||||
return m_ResourceManager.LoadAssetGetOperation<T>(location, needCache);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步加载资源并获取句柄。
|
||||
/// </summary>
|
||||
/// <param name="location">资源的定位地址。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <typeparam name="T">要加载资源的类型。</typeparam>
|
||||
/// <returns>异步加载资源句柄。</returns>
|
||||
public AssetOperationHandle LoadAssetAsyncHandle<T>(string location) where T : UnityEngine.Object
|
||||
public AssetOperationHandle LoadAssetAsyncHandle<T>(string location, bool needCache = false) where T : UnityEngine.Object
|
||||
{
|
||||
return m_ResourceManager.LoadAssetAsyncHandle<T>(location);
|
||||
return m_ResourceManager.LoadAssetAsyncHandle<T>(location, needCache);
|
||||
}
|
||||
|
||||
|
||||
@@ -611,11 +618,12 @@ namespace TEngine
|
||||
/// <param name="location">资源的定位地址。</param>
|
||||
/// <param name="cancellationToken">取消操作Token。</param>
|
||||
/// <param name="needInstance">是否需要实例化。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <typeparam name="T">要加载资源的类型。</typeparam>
|
||||
/// <returns>异步资源实例。</returns>
|
||||
public async UniTask<T> LoadAssetAsync<T>(string location, CancellationToken cancellationToken = default, bool needInstance = true) where T : UnityEngine.Object
|
||||
public async UniTask<T> LoadAssetAsync<T>(string location, CancellationToken cancellationToken = default, bool needInstance = true, bool needCache = false) where T : UnityEngine.Object
|
||||
{
|
||||
return await m_ResourceManager.LoadAssetAsync<T>(location, cancellationToken, needInstance);
|
||||
return await m_ResourceManager.LoadAssetAsync<T>(location, cancellationToken, needInstance, needCache);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -623,10 +631,11 @@ namespace TEngine
|
||||
/// </summary>
|
||||
/// <param name="location">要加载的游戏物体名称。</param>
|
||||
/// <param name="cancellationToken">取消操作Token。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <returns>异步游戏物体实例。</returns>
|
||||
public async UniTask<GameObject> LoadGameObjectAsync(string location, CancellationToken cancellationToken = default)
|
||||
public async UniTask<GameObject> LoadGameObjectAsync(string location, CancellationToken cancellationToken = default, bool needCache = false)
|
||||
{
|
||||
return await m_ResourceManager.LoadGameObjectAsync(location, cancellationToken);
|
||||
return await m_ResourceManager.LoadGameObjectAsync(location, cancellationToken, needCache);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -635,10 +644,11 @@ namespace TEngine
|
||||
/// <param name="location">资源定位地址。</param>
|
||||
/// <param name="parent">父节点位置。</param>
|
||||
/// <param name="cancellationToken">取消操作Token。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <returns>异步游戏物体实例。</returns>
|
||||
public async UniTask<GameObject> LoadGameObjectAsync(string location, Transform parent, CancellationToken cancellationToken = default)
|
||||
public async UniTask<GameObject> LoadGameObjectAsync(string location, Transform parent, CancellationToken cancellationToken = default, bool needCache = false)
|
||||
{
|
||||
return await m_ResourceManager.LoadGameObjectAsync(location, parent, cancellationToken);
|
||||
return await m_ResourceManager.LoadGameObjectAsync(location, parent, cancellationToken, needCache);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@@ -400,7 +400,7 @@ namespace TEngine
|
||||
throw new Exception($"Window {type.FullName} not found {nameof(WindowAttribute)} attribute.");
|
||||
|
||||
string assetName = string.IsNullOrEmpty(attribute.Location) ? type.Name : attribute.Location;
|
||||
window.Init(type.FullName, attribute.WindowLayer, attribute.FullScreen, assetName, attribute.FromResources);
|
||||
window.Init(type.FullName, attribute.WindowLayer, attribute.FullScreen, assetName, attribute.FromResources, attribute.NeedCache);
|
||||
return window;
|
||||
}
|
||||
|
||||
|
@@ -67,6 +67,11 @@ namespace TEngine
|
||||
/// </summary>
|
||||
public bool FromResources { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否需要缓存。
|
||||
/// </summary>
|
||||
public bool NeedCache { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 自定义数据。
|
||||
/// </summary>
|
||||
@@ -221,13 +226,14 @@ namespace TEngine
|
||||
|
||||
#endregion
|
||||
|
||||
public void Init(string name, int layer, bool fullScreen, string assetName, bool fromResources)
|
||||
public void Init(string name, int layer, bool fullScreen, string assetName, bool fromResources, bool needCache = false)
|
||||
{
|
||||
WindowName = name;
|
||||
WindowLayer = layer;
|
||||
FullScreen = fullScreen;
|
||||
AssetName = assetName;
|
||||
FromResources = fromResources;
|
||||
NeedCache = needCache;
|
||||
}
|
||||
|
||||
internal void TryInvoke(System.Action<UIWindow> prepareCallback, System.Object[] userDatas)
|
||||
@@ -249,7 +255,7 @@ namespace TEngine
|
||||
this.userDatas = userDatas;
|
||||
if (!FromResources)
|
||||
{
|
||||
GameModule.Resource.LoadAssetAsync<GameObject>(location, Handle_Completed);
|
||||
GameModule.Resource.LoadAssetAsync<GameObject>(location, Handle_Completed, needCache: NeedCache);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -392,6 +398,10 @@ namespace TEngine
|
||||
|
||||
// 实例化对象
|
||||
var panel = handle.InstantiateSync(UIModule.UIRootStatic);
|
||||
if (!NeedCache)
|
||||
{
|
||||
AssetReference.BindAssetReference(panel, handle, AssetName);
|
||||
}
|
||||
Handle_Completed(panel);
|
||||
}
|
||||
|
||||
|
@@ -37,31 +37,41 @@ namespace TEngine
|
||||
/// </summary>
|
||||
public readonly bool FromResources;
|
||||
|
||||
public WindowAttribute(int windowLayer, string location = "", bool fullScreen = false)
|
||||
/// <summary>
|
||||
/// 需要缓存。
|
||||
/// <remarks>关闭界面不立刻释放资源。</remarks>
|
||||
/// </summary>
|
||||
public readonly bool NeedCache;
|
||||
|
||||
public WindowAttribute(int windowLayer, string location = "", bool fullScreen = false,bool needCache = false)
|
||||
{
|
||||
WindowLayer = windowLayer;
|
||||
Location = location;
|
||||
FullScreen = fullScreen;
|
||||
NeedCache = needCache;
|
||||
}
|
||||
|
||||
public WindowAttribute(UILayer windowLayer, string location = "", bool fullScreen = false)
|
||||
public WindowAttribute(UILayer windowLayer, string location = "", bool fullScreen = false,bool needCache = false)
|
||||
{
|
||||
WindowLayer = (int)windowLayer;
|
||||
Location = location;
|
||||
FullScreen = fullScreen;
|
||||
NeedCache = needCache;
|
||||
}
|
||||
|
||||
public WindowAttribute(UILayer windowLayer, bool fromResources, bool fullScreen = false)
|
||||
public WindowAttribute(UILayer windowLayer, bool fromResources, bool fullScreen = false,bool needCache = false)
|
||||
{
|
||||
WindowLayer = (int)windowLayer;
|
||||
FromResources = fromResources;
|
||||
NeedCache = needCache;
|
||||
}
|
||||
|
||||
public WindowAttribute(UILayer windowLayer, bool fromResources, string location, bool fullScreen = false)
|
||||
public WindowAttribute(UILayer windowLayer, bool fromResources, string location, bool fullScreen = false,bool needCache = false)
|
||||
{
|
||||
WindowLayer = (int)windowLayer;
|
||||
FromResources = fromResources;
|
||||
Location = location;
|
||||
NeedCache = needCache;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user