diff --git a/UnityProject/Assets/TEngine/Runtime/Modules/ResourceModule/IResourceManager.cs b/UnityProject/Assets/TEngine/Runtime/Modules/ResourceModule/IResourceManager.cs
index 93a3b2ff..25e6f2a2 100644
--- a/UnityProject/Assets/TEngine/Runtime/Modules/ResourceModule/IResourceManager.cs
+++ b/UnityProject/Assets/TEngine/Runtime/Modules/ResourceModule/IResourceManager.cs
@@ -2,7 +2,6 @@
using System.Threading;
using Cysharp.Threading.Tasks;
using UnityEngine;
-using UnityEngine.SceneManagement;
using YooAsset;
namespace TEngine
@@ -217,11 +216,11 @@ namespace TEngine
/// 同步加载游戏物体并实例化。
///
/// 资源的定位地址。
- /// 指定资源包的名称。不传使用默认资源包
/// 资源实例父节点。
+ /// 指定资源包的名称。不传使用默认资源包
/// 资源实例。
/// 会实例化资源到场景,无需主动UnloadAsset,Destroy时自动UnloadAsset。
- GameObject LoadGameObject(string location, string packageName = "", Transform parent = null);
+ GameObject LoadGameObject(string location, Transform parent = null, string packageName = "");
///
/// 异步加载资源。
@@ -262,11 +261,11 @@ namespace TEngine
/// 异步加载游戏物体并实例化。
///
/// 资源定位地址。
+ /// 资源实例父节点。
/// 取消操作Token。
/// 指定资源包的名称。不传使用默认资源包
- /// 资源实例父节点。
/// 异步游戏物体实例。
/// 会实例化资源到场景,无需主动UnloadAsset,Destroy时自动UnloadAsset。
- UniTask LoadGameObjectAsync(string location, CancellationToken cancellationToken = default, string packageName = "", Transform parent = null);
+ UniTask LoadGameObjectAsync(string location, Transform parent = null, CancellationToken cancellationToken = default, string packageName = "");
}
}
\ No newline at end of file
diff --git a/UnityProject/Assets/TEngine/Runtime/Modules/ResourceModule/ResourceManager.cs b/UnityProject/Assets/TEngine/Runtime/Modules/ResourceModule/ResourceManager.cs
index f4baadbe..ca094062 100644
--- a/UnityProject/Assets/TEngine/Runtime/Modules/ResourceModule/ResourceManager.cs
+++ b/UnityProject/Assets/TEngine/Runtime/Modules/ResourceModule/ResourceManager.cs
@@ -14,7 +14,6 @@ namespace TEngine
internal sealed partial class ResourceManager : ModuleImp, IResourceManager
{
#region Propreties
-
///
/// 资源包名称。
///
@@ -532,7 +531,7 @@ namespace TEngine
return ret;
}
- public GameObject LoadGameObject(string location, string packageName = "", Transform parent = null)
+ public GameObject LoadGameObject(string location, Transform parent = null, string packageName = "")
{
if (string.IsNullOrEmpty(location))
{
@@ -663,8 +662,7 @@ namespace TEngine
return handle.AssetObject as T;
}
- public async UniTask LoadGameObjectAsync(string location, CancellationToken cancellationToken = default, string packageName = "",
- Transform parent = null)
+ public async UniTask LoadGameObjectAsync(string location, Transform parent = null, CancellationToken cancellationToken = default, string packageName = "")
{
if (string.IsNullOrEmpty(location))
{
@@ -896,12 +894,33 @@ namespace TEngine
}
}
}
-
+
+ private readonly TimeoutController _timeoutController = new TimeoutController();
+
private async UniTask TryWaitingLoading(string assetObjectKey)
{
if (_assetLoadingList.Contains(assetObjectKey))
{
- await UniTask.WaitUntil(() => !_assetLoadingList.Contains(assetObjectKey), cancellationToken:CancellationToken);
+ try
+ {
+ await UniTask.WaitUntil(
+ () => !_assetLoadingList.Contains(assetObjectKey),
+ cancellationToken:CancellationToken)
+#if UNITY_EDITOR
+ .AttachExternalCancellation(_timeoutController.Timeout(TimeSpan.FromSeconds(60)));
+ _timeoutController.Reset();
+#else
+ ;
+#endif
+
+ }
+ catch (OperationCanceledException ex)
+ {
+ if (_timeoutController.IsTimeout())
+ {
+ Log.Error($"LoadAssetAsync Waiting {assetObjectKey} timeout. reason:{ex.Message}");
+ }
+ }
}
}
#endregion
diff --git a/UnityProject/Assets/TEngine/Runtime/Modules/ResourceModule/ResourceModule.cs b/UnityProject/Assets/TEngine/Runtime/Modules/ResourceModule/ResourceModule.cs
index 48c24101..bd85d52f 100644
--- a/UnityProject/Assets/TEngine/Runtime/Modules/ResourceModule/ResourceModule.cs
+++ b/UnityProject/Assets/TEngine/Runtime/Modules/ResourceModule/ResourceModule.cs
@@ -509,10 +509,10 @@ namespace TEngine
/// 同步加载游戏物体并实例化。
///
/// 资源的定位地址。
- /// 指定资源包的名称。不传使用默认资源包。
/// 资源实例父节点。
+ /// 指定资源包的名称。不传使用默认资源包。
/// 资源实例。
- public GameObject LoadGameObject(string location, string packageName = "", Transform parent = null)
+ public GameObject LoadGameObject(string location, Transform parent = null, string packageName = "")
{
if (string.IsNullOrEmpty(location))
{
@@ -520,7 +520,7 @@ namespace TEngine
return null;
}
- return m_ResourceManager.LoadGameObject(location, packageName, parent);
+ return m_ResourceManager.LoadGameObject(location, parent, packageName);
}
///
@@ -565,13 +565,12 @@ namespace TEngine
/// 异步加载游戏物体并实例化。
///
/// 资源定位地址。
+ /// 资源实例父节点。
/// 取消操作Token。
/// 指定资源包的名称。不传使用默认资源包。
- /// 资源实例父节点。
/// 异步游戏物体实例。
- public async UniTask LoadGameObjectAsync(string location, CancellationToken cancellationToken = default,
- string packageName = "",
- Transform parent = null)
+ public async UniTask LoadGameObjectAsync(string location, Transform parent = null, CancellationToken cancellationToken = default,
+ string packageName = "")
{
if (string.IsNullOrEmpty(location))
{
@@ -579,7 +578,7 @@ namespace TEngine
return null;
}
- return await m_ResourceManager.LoadGameObjectAsync(location, cancellationToken, packageName, parent);
+ return await m_ResourceManager.LoadGameObjectAsync(location, parent, cancellationToken, packageName);
}
internal AssetHandle LoadAssetGetOperation(string location,
diff --git a/UnityProject/Assets/TEngine/Runtime/Modules/UIModule/UIBase.cs b/UnityProject/Assets/TEngine/Runtime/Modules/UIModule/UIBase.cs
index 1bebd941..3459a460 100644
--- a/UnityProject/Assets/TEngine/Runtime/Modules/UIModule/UIBase.cs
+++ b/UnityProject/Assets/TEngine/Runtime/Modules/UIModule/UIBase.cs
@@ -331,7 +331,7 @@ namespace TEngine
/// UIWidget实例。
public async UniTask CreateWidgetByPathAsync(Transform parentTrans, string assetLocation, bool visible = true) where T : UIWidget, new()
{
- GameObject goInst = await GameModule.Resource.LoadGameObjectAsync(assetLocation, gameObject.GetCancellationTokenOnDestroy(), parent: parentTrans);
+ GameObject goInst = await GameModule.Resource.LoadGameObjectAsync(assetLocation, parentTrans, gameObject.GetCancellationTokenOnDestroy());
return CreateWidget(goInst, visible);
}