diff --git a/src/UniTask/Assets/Plugins/UniTask/Runtime/External/Addressables/AddressablesAsyncExtensions.cs b/src/UniTask/Assets/Plugins/UniTask/Runtime/External/Addressables/AddressablesAsyncExtensions.cs index a0ca8a1f..0f3a25c8 100644 --- a/src/UniTask/Assets/Plugins/UniTask/Runtime/External/Addressables/AddressablesAsyncExtensions.cs +++ b/src/UniTask/Assets/Plugins/UniTask/Runtime/External/Addressables/AddressablesAsyncExtensions.cs @@ -7,6 +7,7 @@ using System.Runtime.CompilerServices; using System.Runtime.ExceptionServices; using System.Threading; +using UnityEngine.AddressableAssets; using UnityEngine.ResourceManagement.AsyncOperations; namespace Cysharp.Threading.Tasks @@ -171,6 +172,10 @@ void Continuation(AsyncOperationHandle _) completed = true; if (cancellationToken.IsCancellationRequested) { + If (handle.IsValid()) + { + Addressables.Release(handle); + } core.TrySetCanceled(cancellationToken); } else if (handle.Status == AsyncOperationStatus.Failed) @@ -215,6 +220,10 @@ public bool MoveNext() if (cancellationToken.IsCancellationRequested) { completed = true; + if (handle.IsValid()) + { + Addressables.Release(handle); + } core.TrySetCanceled(cancellationToken); return false; } @@ -353,6 +362,10 @@ void Continuation(AsyncOperationHandle argHandle) completed = true; if (cancellationToken.IsCancellationRequested) { + if (handle.IsValid()) + { + Addressables.Release(handle); + } core.TrySetCanceled(cancellationToken); } else if (argHandle.Status == AsyncOperationStatus.Failed) @@ -402,6 +415,10 @@ public bool MoveNext() if (cancellationToken.IsCancellationRequested) { completed = true; + if (handle.IsValid()) + { + Addressables.Release(handle); + } core.TrySetCanceled(cancellationToken); return false; } diff --git a/src/UniTask/Assets/Plugins/UniTask/Runtime/External/Addressables/UniTask.Addressables.asmdef b/src/UniTask/Assets/Plugins/UniTask/Runtime/External/Addressables/UniTask.Addressables.asmdef index 0439df75..faed8eca 100644 --- a/src/UniTask/Assets/Plugins/UniTask/Runtime/External/Addressables/UniTask.Addressables.asmdef +++ b/src/UniTask/Assets/Plugins/UniTask/Runtime/External/Addressables/UniTask.Addressables.asmdef @@ -2,7 +2,8 @@ "name": "UniTask.Addressables", "references": [ "UniTask", - "Unity.ResourceManager" + "Unity.ResourceManager", + "Unity.Addressables" ], "includePlatforms": [], "excludePlatforms": [],