From 1e39b1af6d8baacfeda5bd8d41c1714f32fa1968 Mon Sep 17 00:00:00 2001 From: Y-way Date: Tue, 28 Jun 2022 19:17:47 +0800 Subject: [PATCH 1/2] =?UTF-8?q?AssetOperationHandle=E7=B1=BB=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E4=BE=BF=E6=8D=B7=E6=96=B9=E6=B3=95,=E4=BE=BF?= =?UTF-8?q?=E4=BA=8E=E9=93=BE=E5=BC=8F=E7=BC=96=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit TextAsset asset; YooAssets.LoadAssetAsync(name).WaitForAsyncOperationComplete().GetAssetObjet(out asset).Release(); YooAssets.LoadAssetAsync(name).Completed += handler => { handler.GetAssetObjet(out asset).Release(); }; --- .../Handles/AssetOperationHandle.cs | 38 ++++++++++++++----- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/Assets/YooAsset/Runtime/AssetSystem/Handles/AssetOperationHandle.cs b/Assets/YooAsset/Runtime/AssetSystem/Handles/AssetOperationHandle.cs index 7083e3c..94c8b1a 100644 --- a/Assets/YooAsset/Runtime/AssetSystem/Handles/AssetOperationHandle.cs +++ b/Assets/YooAsset/Runtime/AssetSystem/Handles/AssetOperationHandle.cs @@ -49,21 +49,41 @@ namespace YooAsset return Provider.AssetObject; } } - + /// + /// 获取资源对象 + /// + /// + /// + /// + public AssetOperationHandle GetAssetObjet(out TAsset asset) where TAsset : UnityEngine.Object + { + asset = AssetObject as TAsset; + return this; + } /// /// 等待异步执行完毕 /// - public void WaitForAsyncComplete() + public AssetOperationHandle WaitForAsyncOperationComplete() { if (IsValid == false) - return; + return this; Provider.WaitForAsyncComplete(); + return this; } + /// + /// 等待异步执行完毕 + /// + public void WaitForAsyncComplete() + { + if(IsValid == false) + return; + Provider.WaitForAsyncComplete(); + } - /// - /// 释放资源句柄 - /// - public void Release() + /// + /// 释放资源句柄 + /// + public void Release() { this.ReleaseInternal(); } @@ -109,8 +129,6 @@ namespace YooAsset { return InstantiateAsyncInternal(position, rotation, parent, true); } - - private GameObject InstantiateSyncInternal(Vector3 position, Quaternion rotation, Transform parent, bool setPositionRotation) { if (IsValid == false) @@ -142,4 +160,4 @@ namespace YooAsset return operation; } } -} \ No newline at end of file +} From fee6e8f4dd2302d9ad1b75ed6552c3d9fa7bd2c9 Mon Sep 17 00:00:00 2001 From: Y-way Date: Tue, 28 Jun 2022 19:45:37 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=A4=B1=E8=B4=A5?= =?UTF-8?q?=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Runtime/AssetSystem/Handles/AssetOperationHandle.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Assets/YooAsset/Runtime/AssetSystem/Handles/AssetOperationHandle.cs b/Assets/YooAsset/Runtime/AssetSystem/Handles/AssetOperationHandle.cs index 94c8b1a..add1558 100644 --- a/Assets/YooAsset/Runtime/AssetSystem/Handles/AssetOperationHandle.cs +++ b/Assets/YooAsset/Runtime/AssetSystem/Handles/AssetOperationHandle.cs @@ -57,6 +57,10 @@ namespace YooAsset /// public AssetOperationHandle GetAssetObjet(out TAsset asset) where TAsset : UnityEngine.Object { + if(Status != EOperationStatus.Succeed) + { + YooLogger.Warning($"The {Provider.MainAssetInfo.AssetPath}[{Provider.MainAssetInfo.AssetType}] is not success.Error[{Provider.LastError}]"); + } asset = AssetObject as TAsset; return this; }