From d75c1c8c9395ba950a8b67ca2569edd131e49f72 Mon Sep 17 00:00:00 2001 From: ALEXTANG <574809918@qq.com> Date: Mon, 15 Apr 2024 19:37:42 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8D=87=E7=BA=A7YooAsset->2.1.1=E3=80=81UniTa?= =?UTF-8?q?sk->2.5.4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 升级YooAsset->2.1.1、UniTask->2.5.4 --- .../Editor/Resource/ExtensionFilterRule.cs | 14 ++ .../Resource/ExtensionFilterRule.cs.meta | 3 + .../UniTask/Editor/SplitterGUILayout.cs.meta | 2 +- .../Editor/UniTaskTrackerTreeView.cs.meta | 2 +- .../Editor/UniTaskTrackerWindow.cs.meta | 2 +- .../AddressablesAsyncExtensions.cs | 164 +++++++++++------- .../Addressables/UniTask.Addressables.asmdef | 3 +- .../UniTask/Runtime/External/DOTween.meta | 2 +- .../DOTween/DOTweenAsyncExtensions.cs.meta | 2 +- .../DOTween/UniTask.DOTween.asmdef.meta | 2 +- .../UniTask/Runtime/External/TextMeshPro.meta | 2 +- ...tMeshProAsyncExtensions.InputField.cs.meta | 2 +- ...tMeshProAsyncExtensions.InputField.tt.meta | 2 +- .../TextMeshProAsyncExtensions.cs.meta | 2 +- .../UniTask.TextMeshPro.asmdef.meta | 2 +- .../UniTask/Runtime/IUniTaskSource.cs | 15 +- .../Packages/UniTask/Runtime/Linq/Merge.cs | 4 +- .../UniTask/Runtime/UniTask.AsValueTask.cs | 104 +++++++++++ .../Runtime/UniTask.AsValueTask.cs.meta | 11 ++ .../Packages/UniTask/Runtime/UniTask.Delay.cs | 54 +++++- .../UniTask/Runtime/UniTask.Factory.cs | 31 +++- .../UniTask/Runtime/UniTask.WaitUntil.cs | 43 ++++- .../Packages/UniTask/Runtime/UniTask.cs | 14 +- .../UniTask/Runtime/UniTaskExtensions.cs | 2 +- ...cExtensions.AssetBundleRequestAllAssets.cs | 26 +-- .../UnityAsyncExtensions.AsyncGPUReadback.cs | 9 +- .../UniTask/Runtime/UnityAsyncExtensions.cs | 133 +++++++------- .../UniTask/Runtime/UnityAsyncExtensions.tt | 47 ++--- .../UniTask/Runtime/_InternalVisibleTo.cs | 3 +- UnityProject/Packages/UniTask/package.json | 2 +- .../AssetBundleBuilderHelper.cs | 2 +- .../BaseTasks/TaskCreateReport.cs | 2 +- .../BuiltinBuildPipelineViewer.cs | 4 +- .../RawfileBuildpipelineViewer.cs | 4 +- .../AssetBundleCollector.cs | 35 +--- .../AssetBundleCollectorConfig.cs | 25 ++- .../AssetBundleCollectorPackage.cs | 29 +++- .../AssetBundleCollectorSetting.cs | 5 +- .../AssetBundleCollectorSettingData.cs | 60 +++++++ .../AssetBundleCollectorWindow.cs | 54 ++++-- .../AssetBundleCollectorWindow.uxml | 1 - .../AssetBundleCollector/CollectCommand.cs | 16 +- .../CollectRules/IIgnoreRule.cs | 11 ++ .../CollectRules/IIgnoreRule.cs.meta | 11 ++ .../DefaultRules/DefaultFilterRule.cs | 25 +-- .../DefaultRules/DefaultIgnoreRule.cs | 82 +++++++++ .../DefaultRules/DefaultIgnoreRule.cs.meta | 11 ++ .../DefaultRules/DefaultPackRule.cs | 12 ++ .../AssetBundleReporter/ReportSummary.cs | 2 +- .../VisualViewers/ReporterSummaryViewer.cs | 2 +- .../Editor/Extension/YooAssetEditor.meta | 8 + .../{ => YooAssetEditor}/CustomPackRule.cs | 0 .../CustomPackRule.cs.meta | 0 .../PackageComparator.meta | 0 .../PackageComparatorWindow.cs | 0 .../PackageComparatorWindow.cs.meta | 0 .../{ => YooAssetEditor}/PackageImporter.meta | 0 .../PackageImporter/PackageImporterWindow.cs | 0 .../PackageImporterWindow.cs.meta | 0 .../ShaderVariantCollector.meta | 0 .../ShaderVariantCollectionHelper.cs | 0 .../ShaderVariantCollectionHelper.cs.meta | 0 .../ShaderVariantCollectionManifest.cs | 0 .../ShaderVariantCollectionManifest.cs.meta | 0 .../ShaderVariantCollector.cs | 0 .../ShaderVariantCollector.cs.meta | 0 .../ShaderVariantCollectorSetting.cs | 0 .../ShaderVariantCollectorSetting.cs.meta | 0 .../ShaderVariantCollectorWindow.cs | 0 .../ShaderVariantCollectorWindow.cs.meta | 0 .../ShaderVariantCollectorWindow.uxml | 0 .../ShaderVariantCollectorWindow.uxml.meta | 0 .../Runtime/CacheSystem/CacheHelper.cs | 2 +- .../Runtime/CacheSystem/PersistentHelper.cs | 2 + .../Runtime/CacheSystem/PersistentManager.cs | 8 +- .../YooAsset/Runtime/InitializeParameters.cs | 5 + .../ResourceManager/Handle/SceneHandle.cs | 27 ++- .../Operation/UnloadSceneOperation.cs | 16 ++ .../Provider/BundledSceneProvider.cs | 24 ++- .../Provider/DatabaseSceneProvider.cs | 24 ++- .../Operation/InitializationOperation.cs | 1 + .../Internal/LoadCacheManifestOperation.cs | 2 +- .../UpdatePackageManifestOperation.cs | 1 - .../PlayMode/WebPlayModeImpl.cs | 22 +-- .../ResourcePackage/ResourcePackage.cs | 3 +- .../Runtime/Services/IWechatQueryServices.cs | 15 ++ .../Services/IWechatQueryServices.cs.meta | 11 ++ .../YooAsset/Runtime/Utility/YooUtility.cs | 48 +++-- 88 files changed, 955 insertions(+), 361 deletions(-) create mode 100644 UnityProject/Assets/TEngine/Editor/Resource/ExtensionFilterRule.cs create mode 100644 UnityProject/Assets/TEngine/Editor/Resource/ExtensionFilterRule.cs.meta create mode 100644 UnityProject/Packages/UniTask/Runtime/UniTask.AsValueTask.cs create mode 100644 UnityProject/Packages/UniTask/Runtime/UniTask.AsValueTask.cs.meta create mode 100644 UnityProject/Packages/YooAsset/Editor/AssetBundleCollector/CollectRules/IIgnoreRule.cs create mode 100644 UnityProject/Packages/YooAsset/Editor/AssetBundleCollector/CollectRules/IIgnoreRule.cs.meta create mode 100644 UnityProject/Packages/YooAsset/Editor/AssetBundleCollector/DefaultRules/DefaultIgnoreRule.cs create mode 100644 UnityProject/Packages/YooAsset/Editor/AssetBundleCollector/DefaultRules/DefaultIgnoreRule.cs.meta create mode 100644 UnityProject/Packages/YooAsset/Editor/Extension/YooAssetEditor.meta rename UnityProject/Packages/YooAsset/Editor/Extension/{ => YooAssetEditor}/CustomPackRule.cs (100%) rename UnityProject/Packages/YooAsset/Editor/Extension/{ => YooAssetEditor}/CustomPackRule.cs.meta (100%) rename UnityProject/Packages/YooAsset/Editor/Extension/{ => YooAssetEditor}/PackageComparator.meta (100%) rename UnityProject/Packages/YooAsset/Editor/Extension/{ => YooAssetEditor}/PackageComparator/PackageComparatorWindow.cs (100%) rename UnityProject/Packages/YooAsset/Editor/Extension/{ => YooAssetEditor}/PackageComparator/PackageComparatorWindow.cs.meta (100%) rename UnityProject/Packages/YooAsset/Editor/Extension/{ => YooAssetEditor}/PackageImporter.meta (100%) rename UnityProject/Packages/YooAsset/Editor/Extension/{ => YooAssetEditor}/PackageImporter/PackageImporterWindow.cs (100%) rename UnityProject/Packages/YooAsset/Editor/Extension/{ => YooAssetEditor}/PackageImporter/PackageImporterWindow.cs.meta (100%) rename UnityProject/Packages/YooAsset/Editor/Extension/{ => YooAssetEditor}/ShaderVariantCollector.meta (100%) rename UnityProject/Packages/YooAsset/Editor/Extension/{ => YooAssetEditor}/ShaderVariantCollector/ShaderVariantCollectionHelper.cs (100%) rename UnityProject/Packages/YooAsset/Editor/Extension/{ => YooAssetEditor}/ShaderVariantCollector/ShaderVariantCollectionHelper.cs.meta (100%) rename UnityProject/Packages/YooAsset/Editor/Extension/{ => YooAssetEditor}/ShaderVariantCollector/ShaderVariantCollectionManifest.cs (100%) rename UnityProject/Packages/YooAsset/Editor/Extension/{ => YooAssetEditor}/ShaderVariantCollector/ShaderVariantCollectionManifest.cs.meta (100%) rename UnityProject/Packages/YooAsset/Editor/Extension/{ => YooAssetEditor}/ShaderVariantCollector/ShaderVariantCollector.cs (100%) rename UnityProject/Packages/YooAsset/Editor/Extension/{ => YooAssetEditor}/ShaderVariantCollector/ShaderVariantCollector.cs.meta (100%) rename UnityProject/Packages/YooAsset/Editor/Extension/{ => YooAssetEditor}/ShaderVariantCollector/ShaderVariantCollectorSetting.cs (100%) rename UnityProject/Packages/YooAsset/Editor/Extension/{ => YooAssetEditor}/ShaderVariantCollector/ShaderVariantCollectorSetting.cs.meta (100%) rename UnityProject/Packages/YooAsset/Editor/Extension/{ => YooAssetEditor}/ShaderVariantCollector/ShaderVariantCollectorWindow.cs (100%) rename UnityProject/Packages/YooAsset/Editor/Extension/{ => YooAssetEditor}/ShaderVariantCollector/ShaderVariantCollectorWindow.cs.meta (100%) rename UnityProject/Packages/YooAsset/Editor/Extension/{ => YooAssetEditor}/ShaderVariantCollector/ShaderVariantCollectorWindow.uxml (100%) rename UnityProject/Packages/YooAsset/Editor/Extension/{ => YooAssetEditor}/ShaderVariantCollector/ShaderVariantCollectorWindow.uxml.meta (100%) create mode 100644 UnityProject/Packages/YooAsset/Runtime/Services/IWechatQueryServices.cs create mode 100644 UnityProject/Packages/YooAsset/Runtime/Services/IWechatQueryServices.cs.meta diff --git a/UnityProject/Assets/TEngine/Editor/Resource/ExtensionFilterRule.cs b/UnityProject/Assets/TEngine/Editor/Resource/ExtensionFilterRule.cs new file mode 100644 index 00000000..486ef394 --- /dev/null +++ b/UnityProject/Assets/TEngine/Editor/Resource/ExtensionFilterRule.cs @@ -0,0 +1,14 @@ +using System.IO; +using YooAsset.Editor; + +namespace UnityGameFramework.Editor +{ + [DisplayName("收集着色器")] + public class CollectShader : IFilterRule + { + public bool IsCollectAsset(FilterRuleData data) + { + return Path.GetExtension(data.AssetPath) == ".shader"; + } + } +} \ No newline at end of file diff --git a/UnityProject/Assets/TEngine/Editor/Resource/ExtensionFilterRule.cs.meta b/UnityProject/Assets/TEngine/Editor/Resource/ExtensionFilterRule.cs.meta new file mode 100644 index 00000000..627cf7f8 --- /dev/null +++ b/UnityProject/Assets/TEngine/Editor/Resource/ExtensionFilterRule.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 0e7486840c674c42afd16926eb15ad2d +timeCreated: 1708430564 \ No newline at end of file diff --git a/UnityProject/Packages/UniTask/Editor/SplitterGUILayout.cs.meta b/UnityProject/Packages/UniTask/Editor/SplitterGUILayout.cs.meta index e0bdebb2..4d718f4e 100644 --- a/UnityProject/Packages/UniTask/Editor/SplitterGUILayout.cs.meta +++ b/UnityProject/Packages/UniTask/Editor/SplitterGUILayout.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: e046ba353633f1e4b9552aa50e780fe0 +guid: 40ef2e46f900131419e869398a8d3c9d MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/UnityProject/Packages/UniTask/Editor/UniTaskTrackerTreeView.cs.meta b/UnityProject/Packages/UniTask/Editor/UniTaskTrackerTreeView.cs.meta index 0423af00..9b34d7b9 100644 --- a/UnityProject/Packages/UniTask/Editor/UniTaskTrackerTreeView.cs.meta +++ b/UnityProject/Packages/UniTask/Editor/UniTaskTrackerTreeView.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 1973dbb90ca25d94490075246d04549a +guid: 52e2d973a2156674e8c1c9433ed031f7 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/UnityProject/Packages/UniTask/Editor/UniTaskTrackerWindow.cs.meta b/UnityProject/Packages/UniTask/Editor/UniTaskTrackerWindow.cs.meta index e7e2e324..ba1b7045 100644 --- a/UnityProject/Packages/UniTask/Editor/UniTaskTrackerWindow.cs.meta +++ b/UnityProject/Packages/UniTask/Editor/UniTaskTrackerWindow.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 456b7e008397a8c4c81fac6abd52110a +guid: 5bee3e3860e37484aa3b861bf76d129f MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/UnityProject/Packages/UniTask/Runtime/External/Addressables/AddressablesAsyncExtensions.cs b/UnityProject/Packages/UniTask/Runtime/External/Addressables/AddressablesAsyncExtensions.cs index a0ca8a1f..ee1a9e6c 100644 --- a/UnityProject/Packages/UniTask/Runtime/External/Addressables/AddressablesAsyncExtensions.cs +++ b/UnityProject/Packages/UniTask/Runtime/External/Addressables/AddressablesAsyncExtensions.cs @@ -7,6 +7,7 @@ using System; using System.Runtime.CompilerServices; using System.Runtime.ExceptionServices; using System.Threading; +using UnityEngine.AddressableAssets; using UnityEngine.ResourceManagement.AsyncOperations; namespace Cysharp.Threading.Tasks @@ -20,17 +21,12 @@ namespace Cysharp.Threading.Tasks return ToUniTask(handle).GetAwaiter(); } - public static UniTask WithCancellation(this AsyncOperationHandle handle, CancellationToken cancellationToken) + public static UniTask WithCancellation(this AsyncOperationHandle handle, CancellationToken cancellationToken, bool cancelImmediately = false, bool autoReleaseWhenCanceled = false) { - return ToUniTask(handle, cancellationToken: cancellationToken); + return ToUniTask(handle, cancellationToken: cancellationToken, cancelImmediately: cancelImmediately, autoReleaseWhenCanceled: autoReleaseWhenCanceled); } - public static UniTask WithCancellation(this AsyncOperationHandle handle, CancellationToken cancellationToken, bool cancelImmediately) - { - return ToUniTask(handle, cancellationToken: cancellationToken, cancelImmediately: cancelImmediately); - } - - public static UniTask ToUniTask(this AsyncOperationHandle handle, IProgress progress = null, PlayerLoopTiming timing = PlayerLoopTiming.Update, CancellationToken cancellationToken = default(CancellationToken), bool cancelImmediately = false) + public static UniTask ToUniTask(this AsyncOperationHandle handle, IProgress progress = null, PlayerLoopTiming timing = PlayerLoopTiming.Update, CancellationToken cancellationToken = default(CancellationToken), bool cancelImmediately = false, bool autoReleaseWhenCanceled = false) { if (cancellationToken.IsCancellationRequested) return UniTask.FromCanceled(cancellationToken); @@ -49,7 +45,7 @@ namespace Cysharp.Threading.Tasks return UniTask.CompletedTask; } - return new UniTask(AsyncOperationHandleConfiguredSource.Create(handle, timing, progress, cancellationToken, cancelImmediately, out var token), token); + return new UniTask(AsyncOperationHandleConfiguredSource.Create(handle, timing, progress, cancellationToken, cancelImmediately, autoReleaseWhenCanceled, out var token), token); } public struct AsyncOperationHandleAwaiter : ICriticalNotifyCompletion @@ -108,21 +104,23 @@ namespace Cysharp.Threading.Tasks TaskPool.RegisterSizeGetter(typeof(AsyncOperationHandleConfiguredSource), () => pool.Size); } - readonly Action continuationAction; + readonly Action completedCallback; AsyncOperationHandle handle; CancellationToken cancellationToken; CancellationTokenRegistration cancellationTokenRegistration; IProgress progress; + bool autoReleaseWhenCanceled; + bool cancelImmediately; bool completed; UniTaskCompletionSourceCore core; AsyncOperationHandleConfiguredSource() { - continuationAction = Continuation; + completedCallback = HandleCompleted; } - public static IUniTaskSource Create(AsyncOperationHandle handle, PlayerLoopTiming timing, IProgress progress, CancellationToken cancellationToken, bool cancelImmediately, out short token) + public static IUniTaskSource Create(AsyncOperationHandle handle, PlayerLoopTiming timing, IProgress progress, CancellationToken cancellationToken, bool cancelImmediately, bool autoReleaseWhenCanceled, out short token) { if (cancellationToken.IsCancellationRequested) { @@ -137,6 +135,8 @@ namespace Cysharp.Threading.Tasks result.handle = handle; result.progress = progress; result.cancellationToken = cancellationToken; + result.cancelImmediately = cancelImmediately; + result.autoReleaseWhenCanceled = autoReleaseWhenCanceled; result.completed = false; if (cancelImmediately && cancellationToken.CanBeCanceled) @@ -144,6 +144,10 @@ namespace Cysharp.Threading.Tasks result.cancellationTokenRegistration = cancellationToken.RegisterWithoutCaptureExecutionContext(state => { var promise = (AsyncOperationHandleConfiguredSource)state; + if (promise.autoReleaseWhenCanceled && promise.handle.IsValid()) + { + Addressables.Release(promise.handle); + } promise.core.TrySetCanceled(promise.cancellationToken); }, result); } @@ -152,41 +156,56 @@ namespace Cysharp.Threading.Tasks PlayerLoopHelper.AddAction(timing, result); - handle.Completed += result.continuationAction; + handle.Completed += result.completedCallback; token = result.core.Version; return result; } - void Continuation(AsyncOperationHandle _) + void HandleCompleted(AsyncOperationHandle _) { - handle.Completed -= continuationAction; + if (handle.IsValid()) + { + handle.Completed -= completedCallback; + } if (completed) { - TryReturn(); + return; + } + + completed = true; + if (cancellationToken.IsCancellationRequested) + { + if (autoReleaseWhenCanceled && handle.IsValid()) + { + Addressables.Release(handle); + } + core.TrySetCanceled(cancellationToken); + } + else if (handle.Status == AsyncOperationStatus.Failed) + { + core.TrySetException(handle.OperationException); } else { - completed = true; - if (cancellationToken.IsCancellationRequested) - { - core.TrySetCanceled(cancellationToken); - } - else if (handle.Status == AsyncOperationStatus.Failed) - { - core.TrySetException(handle.OperationException); - } - else - { - core.TrySetResult(AsyncUnit.Default); - } + core.TrySetResult(AsyncUnit.Default); } } public void GetResult(short token) { - core.GetResult(token); + try + { + core.GetResult(token); + } + finally + { + if (!(cancelImmediately && cancellationToken.IsCancellationRequested)) + { + TryReturn(); + } + } } public UniTaskStatus GetStatus(short token) @@ -208,13 +227,16 @@ namespace Cysharp.Threading.Tasks { if (completed) { - TryReturn(); return false; } if (cancellationToken.IsCancellationRequested) { completed = true; + if (autoReleaseWhenCanceled && handle.IsValid()) + { + Addressables.Release(handle); + } core.TrySetCanceled(cancellationToken); return false; } @@ -248,17 +270,12 @@ namespace Cysharp.Threading.Tasks return ToUniTask(handle).GetAwaiter(); } - public static UniTask WithCancellation(this AsyncOperationHandle handle, CancellationToken cancellationToken) + public static UniTask WithCancellation(this AsyncOperationHandle handle, CancellationToken cancellationToken, bool cancelImmediately = false, bool autoReleaseWhenCanceled = false) { - return ToUniTask(handle, cancellationToken: cancellationToken); + return ToUniTask(handle, cancellationToken: cancellationToken, cancelImmediately: cancelImmediately, autoReleaseWhenCanceled: autoReleaseWhenCanceled); } - public static UniTask WithCancellation(this AsyncOperationHandle handle, CancellationToken cancellationToken, bool cancelImmediately) - { - return ToUniTask(handle, cancellationToken: cancellationToken, cancelImmediately: cancelImmediately); - } - - public static UniTask ToUniTask(this AsyncOperationHandle handle, IProgress progress = null, PlayerLoopTiming timing = PlayerLoopTiming.Update, CancellationToken cancellationToken = default(CancellationToken), bool cancelImmediately = false) + public static UniTask ToUniTask(this AsyncOperationHandle handle, IProgress progress = null, PlayerLoopTiming timing = PlayerLoopTiming.Update, CancellationToken cancellationToken = default(CancellationToken), bool cancelImmediately = false, bool autoReleaseWhenCanceled = false) { if (cancellationToken.IsCancellationRequested) return UniTask.FromCanceled(cancellationToken); @@ -276,7 +293,7 @@ namespace Cysharp.Threading.Tasks return UniTask.FromResult(handle.Result); } - return new UniTask(AsyncOperationHandleConfiguredSource.Create(handle, timing, progress, cancellationToken, cancelImmediately, out var token), token); + return new UniTask(AsyncOperationHandleConfiguredSource.Create(handle, timing, progress, cancellationToken, cancelImmediately, autoReleaseWhenCanceled, out var token), token); } sealed class AsyncOperationHandleConfiguredSource : IUniTaskSource, IPlayerLoopItem, ITaskPoolNode> @@ -290,21 +307,23 @@ namespace Cysharp.Threading.Tasks TaskPool.RegisterSizeGetter(typeof(AsyncOperationHandleConfiguredSource), () => pool.Size); } - readonly Action> continuationAction; + readonly Action> completedCallback; AsyncOperationHandle handle; CancellationToken cancellationToken; CancellationTokenRegistration cancellationTokenRegistration; IProgress progress; + bool autoReleaseWhenCanceled; + bool cancelImmediately; bool completed; UniTaskCompletionSourceCore core; AsyncOperationHandleConfiguredSource() { - continuationAction = Continuation; + completedCallback = HandleCompleted; } - public static IUniTaskSource Create(AsyncOperationHandle handle, PlayerLoopTiming timing, IProgress progress, CancellationToken cancellationToken, bool cancelImmediately, out short token) + public static IUniTaskSource Create(AsyncOperationHandle handle, PlayerLoopTiming timing, IProgress progress, CancellationToken cancellationToken, bool cancelImmediately, bool autoReleaseWhenCanceled, out short token) { if (cancellationToken.IsCancellationRequested) { @@ -320,12 +339,18 @@ namespace Cysharp.Threading.Tasks result.cancellationToken = cancellationToken; result.completed = false; result.progress = progress; + result.autoReleaseWhenCanceled = autoReleaseWhenCanceled; + result.cancelImmediately = cancelImmediately; if (cancelImmediately && cancellationToken.CanBeCanceled) { result.cancellationTokenRegistration = cancellationToken.RegisterWithoutCaptureExecutionContext(state => { var promise = (AsyncOperationHandleConfiguredSource)state; + if (promise.autoReleaseWhenCanceled && promise.handle.IsValid()) + { + Addressables.Release(promise.handle); + } promise.core.TrySetCanceled(promise.cancellationToken); }, result); } @@ -334,41 +359,53 @@ namespace Cysharp.Threading.Tasks PlayerLoopHelper.AddAction(timing, result); - handle.Completed += result.continuationAction; + handle.Completed += result.completedCallback; token = result.core.Version; return result; } - void Continuation(AsyncOperationHandle argHandle) + void HandleCompleted(AsyncOperationHandle argHandle) { - handle.Completed -= continuationAction; + if (handle.IsValid()) + { + handle.Completed -= completedCallback; + } if (completed) { - TryReturn(); + return; + } + completed = true; + if (cancellationToken.IsCancellationRequested) + { + if (autoReleaseWhenCanceled && handle.IsValid()) + { + Addressables.Release(handle); + } + core.TrySetCanceled(cancellationToken); + } + else if (argHandle.Status == AsyncOperationStatus.Failed) + { + core.TrySetException(argHandle.OperationException); } else { - completed = true; - if (cancellationToken.IsCancellationRequested) - { - core.TrySetCanceled(cancellationToken); - } - else if (argHandle.Status == AsyncOperationStatus.Failed) - { - core.TrySetException(argHandle.OperationException); - } - else - { - core.TrySetResult(argHandle.Result); - } + core.TrySetResult(argHandle.Result); } } public T GetResult(short token) { - return core.GetResult(token); + try + { + return core.GetResult(token); + } + finally + { + if (!(cancelImmediately && cancellationToken.IsCancellationRequested)) + TryReturn(); + } } void IUniTaskSource.GetResult(short token) @@ -395,13 +432,16 @@ namespace Cysharp.Threading.Tasks { if (completed) { - TryReturn(); return false; } if (cancellationToken.IsCancellationRequested) { completed = true; + if (autoReleaseWhenCanceled && handle.IsValid()) + { + Addressables.Release(handle); + } core.TrySetCanceled(cancellationToken); return false; } diff --git a/UnityProject/Packages/UniTask/Runtime/External/Addressables/UniTask.Addressables.asmdef b/UnityProject/Packages/UniTask/Runtime/External/Addressables/UniTask.Addressables.asmdef index 0439df75..faed8eca 100644 --- a/UnityProject/Packages/UniTask/Runtime/External/Addressables/UniTask.Addressables.asmdef +++ b/UnityProject/Packages/UniTask/Runtime/External/Addressables/UniTask.Addressables.asmdef @@ -2,7 +2,8 @@ "name": "UniTask.Addressables", "references": [ "UniTask", - "Unity.ResourceManager" + "Unity.ResourceManager", + "Unity.Addressables" ], "includePlatforms": [], "excludePlatforms": [], diff --git a/UnityProject/Packages/UniTask/Runtime/External/DOTween.meta b/UnityProject/Packages/UniTask/Runtime/External/DOTween.meta index 5368e3d5..c08509af 100644 --- a/UnityProject/Packages/UniTask/Runtime/External/DOTween.meta +++ b/UnityProject/Packages/UniTask/Runtime/External/DOTween.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: d96696960b382384190300495cd26735 +guid: 25cb2f742bfeb1d48a4e65d3140b955d folderAsset: yes DefaultImporter: externalObjects: {} diff --git a/UnityProject/Packages/UniTask/Runtime/External/DOTween/DOTweenAsyncExtensions.cs.meta b/UnityProject/Packages/UniTask/Runtime/External/DOTween/DOTweenAsyncExtensions.cs.meta index 57d37375..63131b04 100644 --- a/UnityProject/Packages/UniTask/Runtime/External/DOTween/DOTweenAsyncExtensions.cs.meta +++ b/UnityProject/Packages/UniTask/Runtime/External/DOTween/DOTweenAsyncExtensions.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: c517968e1258cb649984dddf2c0ad8b0 +guid: 1f448d5bc5b232e4f98d89d5d1832e8e MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/UnityProject/Packages/UniTask/Runtime/External/DOTween/UniTask.DOTween.asmdef.meta b/UnityProject/Packages/UniTask/Runtime/External/DOTween/UniTask.DOTween.asmdef.meta index c22635dd..427fe290 100644 --- a/UnityProject/Packages/UniTask/Runtime/External/DOTween/UniTask.DOTween.asmdef.meta +++ b/UnityProject/Packages/UniTask/Runtime/External/DOTween/UniTask.DOTween.asmdef.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: a40cecb731a38b340b0d3899da286566 +guid: 029c1c1b674aaae47a6841a0b89ad80e AssemblyDefinitionImporter: externalObjects: {} userData: diff --git a/UnityProject/Packages/UniTask/Runtime/External/TextMeshPro.meta b/UnityProject/Packages/UniTask/Runtime/External/TextMeshPro.meta index b23772fa..ac860aa8 100644 --- a/UnityProject/Packages/UniTask/Runtime/External/TextMeshPro.meta +++ b/UnityProject/Packages/UniTask/Runtime/External/TextMeshPro.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 3cc67eb6c366477469fdf07a6922c183 +guid: f89da606bde9a4e4e94ae1189a029887 folderAsset: yes DefaultImporter: externalObjects: {} diff --git a/UnityProject/Packages/UniTask/Runtime/External/TextMeshPro/TextMeshProAsyncExtensions.InputField.cs.meta b/UnityProject/Packages/UniTask/Runtime/External/TextMeshPro/TextMeshProAsyncExtensions.InputField.cs.meta index f3d6d1cd..2e39d2e8 100644 --- a/UnityProject/Packages/UniTask/Runtime/External/TextMeshPro/TextMeshProAsyncExtensions.InputField.cs.meta +++ b/UnityProject/Packages/UniTask/Runtime/External/TextMeshPro/TextMeshProAsyncExtensions.InputField.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 930414e3dd7d9d746a13c3a0f14ba5e7 +guid: 79f4f2475e0b2c44e97ed1dee760627b MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/UnityProject/Packages/UniTask/Runtime/External/TextMeshPro/TextMeshProAsyncExtensions.InputField.tt.meta b/UnityProject/Packages/UniTask/Runtime/External/TextMeshPro/TextMeshProAsyncExtensions.InputField.tt.meta index 11c73fb1..d27b2e05 100644 --- a/UnityProject/Packages/UniTask/Runtime/External/TextMeshPro/TextMeshProAsyncExtensions.InputField.tt.meta +++ b/UnityProject/Packages/UniTask/Runtime/External/TextMeshPro/TextMeshProAsyncExtensions.InputField.tt.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 9a4a4017ce5c23445a882e87e8cb103c +guid: e9bb9fc551a975d44a7180e022a2debe DefaultImporter: externalObjects: {} userData: diff --git a/UnityProject/Packages/UniTask/Runtime/External/TextMeshPro/TextMeshProAsyncExtensions.cs.meta b/UnityProject/Packages/UniTask/Runtime/External/TextMeshPro/TextMeshProAsyncExtensions.cs.meta index e6e6762a..752d125c 100644 --- a/UnityProject/Packages/UniTask/Runtime/External/TextMeshPro/TextMeshProAsyncExtensions.cs.meta +++ b/UnityProject/Packages/UniTask/Runtime/External/TextMeshPro/TextMeshProAsyncExtensions.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: a9cba699cacf633438f41c07916c83d0 +guid: b6ba480edafb67d4e91bb10feb64fae5 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/UnityProject/Packages/UniTask/Runtime/External/TextMeshPro/UniTask.TextMeshPro.asmdef.meta b/UnityProject/Packages/UniTask/Runtime/External/TextMeshPro/UniTask.TextMeshPro.asmdef.meta index 03b40ac3..4b59831d 100644 --- a/UnityProject/Packages/UniTask/Runtime/External/TextMeshPro/UniTask.TextMeshPro.asmdef.meta +++ b/UnityProject/Packages/UniTask/Runtime/External/TextMeshPro/UniTask.TextMeshPro.asmdef.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: d82b75b6a37050140bd967e8499035d8 +guid: dc47925d1a5fa2946bdd37746b2b5d48 AssemblyDefinitionImporter: externalObjects: {} userData: diff --git a/UnityProject/Packages/UniTask/Runtime/IUniTaskSource.cs b/UnityProject/Packages/UniTask/Runtime/IUniTaskSource.cs index 88147811..ad758f1c 100644 --- a/UnityProject/Packages/UniTask/Runtime/IUniTaskSource.cs +++ b/UnityProject/Packages/UniTask/Runtime/IUniTaskSource.cs @@ -1,4 +1,9 @@ #pragma warning disable CS1591 +#pragma warning disable CS0108 + +#if (UNITASK_NETCORE && !NETSTANDARD2_0) || UNITY_2022_3_OR_NEWER +#define SUPPORT_VALUETASK +#endif using System; using System.Runtime.CompilerServices; @@ -19,9 +24,8 @@ namespace Cysharp.Threading.Tasks // similar as IValueTaskSource public interface IUniTaskSource -#if !UNITY_2018_3_OR_NEWER && !NETSTANDARD2_0 +#if SUPPORT_VALUETASK : System.Threading.Tasks.Sources.IValueTaskSource -#pragma warning disable CS0108 #endif { UniTaskStatus GetStatus(short token); @@ -30,8 +34,7 @@ namespace Cysharp.Threading.Tasks UniTaskStatus UnsafeGetStatus(); // only for debug use. -#if !UNITY_2018_3_OR_NEWER && !NETSTANDARD2_0 -#pragma warning restore CS0108 +#if SUPPORT_VALUETASK System.Threading.Tasks.Sources.ValueTaskSourceStatus System.Threading.Tasks.Sources.IValueTaskSource.GetStatus(short token) { @@ -53,13 +56,13 @@ namespace Cysharp.Threading.Tasks } public interface IUniTaskSource : IUniTaskSource -#if !UNITY_2018_3_OR_NEWER && !NETSTANDARD2_0 +#if SUPPORT_VALUETASK , System.Threading.Tasks.Sources.IValueTaskSource #endif { new T GetResult(short token); -#if !UNITY_2018_3_OR_NEWER && !NETSTANDARD2_0 +#if SUPPORT_VALUETASK new public UniTaskStatus GetStatus(short token) { diff --git a/UnityProject/Packages/UniTask/Runtime/Linq/Merge.cs b/UnityProject/Packages/UniTask/Runtime/Linq/Merge.cs index d4ea969a..b74bf252 100644 --- a/UnityProject/Packages/UniTask/Runtime/Linq/Merge.cs +++ b/UnityProject/Packages/UniTask/Runtime/Linq/Merge.cs @@ -27,7 +27,9 @@ namespace Cysharp.Threading.Tasks.Linq public static IUniTaskAsyncEnumerable Merge(this IEnumerable> sources) { - return new Merge(sources.ToArray()); + return sources is IUniTaskAsyncEnumerable[] array + ? new Merge(array) + : new Merge(sources.ToArray()); } public static IUniTaskAsyncEnumerable Merge(params IUniTaskAsyncEnumerable[] sources) diff --git a/UnityProject/Packages/UniTask/Runtime/UniTask.AsValueTask.cs b/UnityProject/Packages/UniTask/Runtime/UniTask.AsValueTask.cs new file mode 100644 index 00000000..ab1e913f --- /dev/null +++ b/UnityProject/Packages/UniTask/Runtime/UniTask.AsValueTask.cs @@ -0,0 +1,104 @@ +#pragma warning disable 0649 + +#if UNITASK_NETCORE || UNITY_2022_3_OR_NEWER +#define SUPPORT_VALUETASK +#endif + +#if SUPPORT_VALUETASK + +using System; +using System.Threading.Tasks; +using System.Threading.Tasks.Sources; + +namespace Cysharp.Threading.Tasks +{ + public static class UniTaskValueTaskExtensions + { + public static ValueTask AsValueTask(this in UniTask task) + { +#if (UNITASK_NETCORE && NETSTANDARD2_0) + return new ValueTask(new UniTaskValueTaskSource(task), 0); +#else + return task; +#endif + } + + public static ValueTask AsValueTask(this in UniTask task) + { +#if (UNITASK_NETCORE && NETSTANDARD2_0) + return new ValueTask(new UniTaskValueTaskSource(task), 0); +#else + return task; +#endif + } + + public static async UniTask AsUniTask(this ValueTask task) + { + return await task; + } + + public static async UniTask AsUniTask(this ValueTask task) + { + await task; + } + +#if (UNITASK_NETCORE && NETSTANDARD2_0) + + class UniTaskValueTaskSource : IValueTaskSource + { + readonly UniTask task; + readonly UniTask.Awaiter awaiter; + + public UniTaskValueTaskSource(UniTask task) + { + this.task = task; + this.awaiter = task.GetAwaiter(); + } + + public void GetResult(short token) + { + awaiter.GetResult(); + } + + public ValueTaskSourceStatus GetStatus(short token) + { + return (ValueTaskSourceStatus)task.Status; + } + + public void OnCompleted(Action continuation, object state, short token, ValueTaskSourceOnCompletedFlags flags) + { + awaiter.SourceOnCompleted(continuation, state); + } + } + + class UniTaskValueTaskSource : IValueTaskSource + { + readonly UniTask task; + readonly UniTask.Awaiter awaiter; + + public UniTaskValueTaskSource(UniTask task) + { + this.task = task; + this.awaiter = task.GetAwaiter(); + } + + public T GetResult(short token) + { + return awaiter.GetResult(); + } + + public ValueTaskSourceStatus GetStatus(short token) + { + return (ValueTaskSourceStatus)task.Status; + } + + public void OnCompleted(Action continuation, object state, short token, ValueTaskSourceOnCompletedFlags flags) + { + awaiter.SourceOnCompleted(continuation, state); + } + } + +#endif + } +} +#endif diff --git a/UnityProject/Packages/UniTask/Runtime/UniTask.AsValueTask.cs.meta b/UnityProject/Packages/UniTask/Runtime/UniTask.AsValueTask.cs.meta new file mode 100644 index 00000000..801bce1c --- /dev/null +++ b/UnityProject/Packages/UniTask/Runtime/UniTask.AsValueTask.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: d38f0478933be42d895c37b862540a1c +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/UnityProject/Packages/UniTask/Runtime/UniTask.Delay.cs b/UnityProject/Packages/UniTask/Runtime/UniTask.Delay.cs index 7f02a1a1..8ac8a29b 100644 --- a/UnityProject/Packages/UniTask/Runtime/UniTask.Delay.cs +++ b/UnityProject/Packages/UniTask/Runtime/UniTask.Delay.cs @@ -208,6 +208,7 @@ namespace Cysharp.Threading.Tasks CancellationToken cancellationToken; CancellationTokenRegistration cancellationTokenRegistration; + bool cancelImmediately; UniTaskCompletionSourceCore core; YieldPromise() @@ -227,6 +228,7 @@ namespace Cysharp.Threading.Tasks } result.cancellationToken = cancellationToken; + result.cancelImmediately = cancelImmediately; if (cancelImmediately && cancellationToken.CanBeCanceled) { @@ -253,7 +255,10 @@ namespace Cysharp.Threading.Tasks } finally { - TryReturn(); + if (!(cancelImmediately && cancellationToken.IsCancellationRequested)) + { + TryReturn(); + } } } @@ -290,6 +295,7 @@ namespace Cysharp.Threading.Tasks core.Reset(); cancellationToken = default; cancellationTokenRegistration.Dispose(); + cancelImmediately = default; return pool.TryPush(this); } } @@ -309,6 +315,7 @@ namespace Cysharp.Threading.Tasks UniTaskCompletionSourceCore core; CancellationToken cancellationToken; CancellationTokenRegistration cancellationTokenRegistration; + bool cancelImmediately; NextFramePromise() { @@ -328,6 +335,7 @@ namespace Cysharp.Threading.Tasks result.frameCount = PlayerLoopHelper.IsMainThread ? Time.frameCount : -1; result.cancellationToken = cancellationToken; + result.cancelImmediately = cancelImmediately; if (cancelImmediately && cancellationToken.CanBeCanceled) { @@ -354,7 +362,10 @@ namespace Cysharp.Threading.Tasks } finally { - TryReturn(); + if (!(cancelImmediately && cancellationToken.IsCancellationRequested)) + { + TryReturn(); + } } } @@ -414,6 +425,7 @@ namespace Cysharp.Threading.Tasks UniTaskCompletionSourceCore core; CancellationToken cancellationToken; CancellationTokenRegistration cancellationTokenRegistration; + bool cancelImmediately; WaitForEndOfFramePromise() { @@ -432,6 +444,7 @@ namespace Cysharp.Threading.Tasks } result.cancellationToken = cancellationToken; + result.cancelImmediately = cancelImmediately; if (cancelImmediately && cancellationToken.CanBeCanceled) { @@ -458,7 +471,10 @@ namespace Cysharp.Threading.Tasks } finally { - TryReturn(); + if (!(cancelImmediately && cancellationToken.IsCancellationRequested)) + { + TryReturn(); + } } } @@ -533,6 +549,7 @@ namespace Cysharp.Threading.Tasks int delayFrameCount; CancellationToken cancellationToken; CancellationTokenRegistration cancellationTokenRegistration; + bool cancelImmediately; int currentFrameCount; UniTaskCompletionSourceCore core; @@ -556,6 +573,7 @@ namespace Cysharp.Threading.Tasks result.delayFrameCount = delayFrameCount; result.cancellationToken = cancellationToken; result.initialFrame = PlayerLoopHelper.IsMainThread ? Time.frameCount : -1; + result.cancelImmediately = cancelImmediately; if (cancelImmediately && cancellationToken.CanBeCanceled) { @@ -582,7 +600,10 @@ namespace Cysharp.Threading.Tasks } finally { - TryReturn(); + if (!(cancelImmediately && cancellationToken.IsCancellationRequested)) + { + TryReturn(); + } } } @@ -653,6 +674,7 @@ namespace Cysharp.Threading.Tasks delayFrameCount = default; cancellationToken = default; cancellationTokenRegistration.Dispose(); + cancelImmediately = default; return pool.TryPush(this); } } @@ -673,6 +695,7 @@ namespace Cysharp.Threading.Tasks float elapsed; CancellationToken cancellationToken; CancellationTokenRegistration cancellationTokenRegistration; + bool cancelImmediately; UniTaskCompletionSourceCore core; @@ -696,6 +719,7 @@ namespace Cysharp.Threading.Tasks result.delayTimeSpan = (float)delayTimeSpan.TotalSeconds; result.cancellationToken = cancellationToken; result.initialFrame = PlayerLoopHelper.IsMainThread ? Time.frameCount : -1; + result.cancelImmediately = cancelImmediately; if (cancelImmediately && cancellationToken.CanBeCanceled) { @@ -722,7 +746,10 @@ namespace Cysharp.Threading.Tasks } finally { - TryReturn(); + if (!(cancelImmediately && cancellationToken.IsCancellationRequested)) + { + TryReturn(); + } } } @@ -775,6 +802,7 @@ namespace Cysharp.Threading.Tasks elapsed = default; cancellationToken = default; cancellationTokenRegistration.Dispose(); + cancelImmediately = default; return pool.TryPush(this); } } @@ -795,6 +823,7 @@ namespace Cysharp.Threading.Tasks int initialFrame; CancellationToken cancellationToken; CancellationTokenRegistration cancellationTokenRegistration; + bool cancelImmediately; UniTaskCompletionSourceCore core; @@ -818,6 +847,7 @@ namespace Cysharp.Threading.Tasks result.delayFrameTimeSpan = (float)delayFrameTimeSpan.TotalSeconds; result.initialFrame = PlayerLoopHelper.IsMainThread ? Time.frameCount : -1; result.cancellationToken = cancellationToken; + result.cancelImmediately = cancelImmediately; if (cancelImmediately && cancellationToken.CanBeCanceled) { @@ -844,7 +874,10 @@ namespace Cysharp.Threading.Tasks } finally { - TryReturn(); + if (!(cancelImmediately && cancellationToken.IsCancellationRequested)) + { + TryReturn(); + } } } @@ -897,6 +930,7 @@ namespace Cysharp.Threading.Tasks elapsed = default; cancellationToken = default; cancellationTokenRegistration.Dispose(); + cancelImmediately = default; return pool.TryPush(this); } } @@ -916,6 +950,7 @@ namespace Cysharp.Threading.Tasks ValueStopwatch stopwatch; CancellationToken cancellationToken; CancellationTokenRegistration cancellationTokenRegistration; + bool cancelImmediately; UniTaskCompletionSourceCore core; @@ -938,6 +973,7 @@ namespace Cysharp.Threading.Tasks result.stopwatch = ValueStopwatch.StartNew(); result.delayTimeSpanTicks = delayTimeSpan.Ticks; result.cancellationToken = cancellationToken; + result.cancelImmediately = cancelImmediately; if (cancelImmediately && cancellationToken.CanBeCanceled) { @@ -964,7 +1000,10 @@ namespace Cysharp.Threading.Tasks } finally { - TryReturn(); + if (!(cancelImmediately && cancellationToken.IsCancellationRequested)) + { + TryReturn(); + } } } @@ -1013,6 +1052,7 @@ namespace Cysharp.Threading.Tasks stopwatch = default; cancellationToken = default; cancellationTokenRegistration.Dispose(); + cancelImmediately = default; return pool.TryPush(this); } } diff --git a/UnityProject/Packages/UniTask/Runtime/UniTask.Factory.cs b/UnityProject/Packages/UniTask/Runtime/UniTask.Factory.cs index 2f6a6a9e..bd66aba8 100644 --- a/UnityProject/Packages/UniTask/Runtime/UniTask.Factory.cs +++ b/UnityProject/Packages/UniTask/Runtime/UniTask.Factory.cs @@ -81,6 +81,16 @@ namespace Cysharp.Threading.Tasks return factory(); } + public static UniTask Create(Func factory, CancellationToken cancellationToken) + { + return factory(cancellationToken); + } + + public static UniTask Create(T state, Func factory) + { + return factory(state); + } + public static UniTask Create(Func> factory) { return factory(); @@ -137,11 +147,19 @@ namespace Cysharp.Threading.Tasks return () => asyncAction(cancellationToken).Forget(); } + /// + /// helper of create add UniTaskVoid to delegate. + /// + public static Action Action(T state, Func asyncAction) + { + return () => asyncAction(state).Forget(); + } + #if UNITY_2018_3_OR_NEWER /// /// Create async void(UniTaskVoid) UnityAction. - /// For exampe: onClick.AddListener(UniTask.UnityAction(async () => { /* */ } )) + /// For example: onClick.AddListener(UniTask.UnityAction(async () => { /* */ } )) /// public static UnityEngine.Events.UnityAction UnityAction(Func asyncAction) { @@ -150,13 +168,22 @@ namespace Cysharp.Threading.Tasks /// /// Create async void(UniTaskVoid) UnityAction. - /// For exampe: onClick.AddListener(UniTask.UnityAction(FooAsync, this.GetCancellationTokenOnDestroy())) + /// For example: onClick.AddListener(UniTask.UnityAction(FooAsync, this.GetCancellationTokenOnDestroy())) /// public static UnityEngine.Events.UnityAction UnityAction(Func asyncAction, CancellationToken cancellationToken) { return () => asyncAction(cancellationToken).Forget(); } + /// + /// Create async void(UniTaskVoid) UnityAction. + /// For example: onClick.AddListener(UniTask.UnityAction(FooAsync, Argument)) + /// + public static UnityEngine.Events.UnityAction UnityAction(T state, Func asyncAction) + { + return () => asyncAction(state).Forget(); + } + #endif /// diff --git a/UnityProject/Packages/UniTask/Runtime/UniTask.WaitUntil.cs b/UnityProject/Packages/UniTask/Runtime/UniTask.WaitUntil.cs index b28a529e..d126199e 100644 --- a/UnityProject/Packages/UniTask/Runtime/UniTask.WaitUntil.cs +++ b/UnityProject/Packages/UniTask/Runtime/UniTask.WaitUntil.cs @@ -49,6 +49,7 @@ namespace Cysharp.Threading.Tasks Func predicate; CancellationToken cancellationToken; CancellationTokenRegistration cancellationTokenRegistration; + bool cancelImmediately; UniTaskCompletionSourceCore core; @@ -70,6 +71,7 @@ namespace Cysharp.Threading.Tasks result.predicate = predicate; result.cancellationToken = cancellationToken; + result.cancelImmediately = cancelImmediately; if (cancelImmediately && cancellationToken.CanBeCanceled) { @@ -96,7 +98,10 @@ namespace Cysharp.Threading.Tasks } finally { - TryReturn(); + if (!(cancelImmediately && cancellationToken.IsCancellationRequested)) + { + TryReturn(); + } } } @@ -147,6 +152,7 @@ namespace Cysharp.Threading.Tasks predicate = default; cancellationToken = default; cancellationTokenRegistration.Dispose(); + cancelImmediately = default; return pool.TryPush(this); } } @@ -165,6 +171,7 @@ namespace Cysharp.Threading.Tasks Func predicate; CancellationToken cancellationToken; CancellationTokenRegistration cancellationTokenRegistration; + bool cancelImmediately; UniTaskCompletionSourceCore core; @@ -212,7 +219,10 @@ namespace Cysharp.Threading.Tasks } finally { - TryReturn(); + if (!(cancelImmediately && cancellationToken.IsCancellationRequested)) + { + TryReturn(); + } } } @@ -263,6 +273,7 @@ namespace Cysharp.Threading.Tasks predicate = default; cancellationToken = default; cancellationTokenRegistration.Dispose(); + cancelImmediately = default; return pool.TryPush(this); } } @@ -280,6 +291,7 @@ namespace Cysharp.Threading.Tasks CancellationToken cancellationToken; CancellationTokenRegistration cancellationTokenRegistration; + bool cancelImmediately; UniTaskCompletionSourceCore core; @@ -287,7 +299,7 @@ namespace Cysharp.Threading.Tasks { } - public static IUniTaskSource Create(CancellationToken cancellationToken, PlayerLoopTiming timing, bool completeImmediately, out short token) + public static IUniTaskSource Create(CancellationToken cancellationToken, PlayerLoopTiming timing, bool cancelImmediately, out short token) { if (cancellationToken.IsCancellationRequested) { @@ -300,8 +312,9 @@ namespace Cysharp.Threading.Tasks } result.cancellationToken = cancellationToken; + result.cancelImmediately = cancelImmediately; - if (completeImmediately && cancellationToken.CanBeCanceled) + if (cancelImmediately && cancellationToken.CanBeCanceled) { result.cancellationTokenRegistration = cancellationToken.RegisterWithoutCaptureExecutionContext(state => { @@ -326,7 +339,10 @@ namespace Cysharp.Threading.Tasks } finally { - TryReturn(); + if (!(cancelImmediately && cancellationToken.IsCancellationRequested)) + { + TryReturn(); + } } } @@ -362,6 +378,7 @@ namespace Cysharp.Threading.Tasks core.Reset(); cancellationToken = default; cancellationTokenRegistration.Dispose(); + cancelImmediately = default; return pool.TryPush(this); } } @@ -385,6 +402,7 @@ namespace Cysharp.Threading.Tasks IEqualityComparer equalityComparer; CancellationToken cancellationToken; CancellationTokenRegistration cancellationTokenRegistration; + bool cancelImmediately; UniTaskCompletionSourceCore core; @@ -410,6 +428,7 @@ namespace Cysharp.Threading.Tasks result.currentValue = monitorFunction(target); result.equalityComparer = equalityComparer ?? UnityEqualityComparer.GetDefault(); result.cancellationToken = cancellationToken; + result.cancelImmediately = cancelImmediately; if (cancelImmediately && cancellationToken.CanBeCanceled) { @@ -436,7 +455,10 @@ namespace Cysharp.Threading.Tasks } finally { - TryReturn(); + if (!(cancelImmediately && cancellationToken.IsCancellationRequested)) + { + TryReturn(); + } } } @@ -497,6 +519,7 @@ namespace Cysharp.Threading.Tasks equalityComparer = default; cancellationToken = default; cancellationTokenRegistration.Dispose(); + cancelImmediately = default; return pool.TryPush(this); } } @@ -519,6 +542,7 @@ namespace Cysharp.Threading.Tasks IEqualityComparer equalityComparer; CancellationToken cancellationToken; CancellationTokenRegistration cancellationTokenRegistration; + bool cancelImmediately; UniTaskCompletionSourceCore core; @@ -543,6 +567,7 @@ namespace Cysharp.Threading.Tasks result.currentValue = monitorFunction(target); result.equalityComparer = equalityComparer ?? UnityEqualityComparer.GetDefault(); result.cancellationToken = cancellationToken; + result.cancelImmediately = cancelImmediately; if (cancelImmediately && cancellationToken.CanBeCanceled) { @@ -569,7 +594,10 @@ namespace Cysharp.Threading.Tasks } finally { - TryReturn(); + if (!(cancelImmediately && cancellationToken.IsCancellationRequested)) + { + TryReturn(); + } } } @@ -630,6 +658,7 @@ namespace Cysharp.Threading.Tasks equalityComparer = default; cancellationToken = default; cancellationTokenRegistration.Dispose(); + cancelImmediately = default; return pool.TryPush(this); } } diff --git a/UnityProject/Packages/UniTask/Runtime/UniTask.cs b/UnityProject/Packages/UniTask/Runtime/UniTask.cs index 8eb2087a..56a8d1fb 100644 --- a/UnityProject/Packages/UniTask/Runtime/UniTask.cs +++ b/UnityProject/Packages/UniTask/Runtime/UniTask.cs @@ -1,6 +1,10 @@ #pragma warning disable CS1591 // Missing XML comment for publicly visible type or member #pragma warning disable CS0436 +#if UNITASK_NETCORE || UNITY_2022_3_OR_NEWER +#define SUPPORT_VALUETASK +#endif + using Cysharp.Threading.Tasks.CompilerServices; using System; using System.Diagnostics; @@ -69,7 +73,7 @@ namespace Cysharp.Threading.Tasks return new UniTask(new IsCanceledSource(source), token); } -#if !UNITY_2018_3_OR_NEWER +#if SUPPORT_VALUETASK public static implicit operator System.Threading.Tasks.ValueTask(in UniTask self) { @@ -78,7 +82,7 @@ namespace Cysharp.Threading.Tasks return default; } -#if NETSTANDARD2_0 +#if (UNITASK_NETCORE && NETSTANDARD2_0) return self.AsValueTask(); #else return new System.Threading.Tasks.ValueTask(self.source, self.token); @@ -118,7 +122,7 @@ namespace Cysharp.Threading.Tasks this.source.GetResult(this.token); return CompletedTasks.AsyncUnit; } - else if(this.source is IUniTaskSource asyncUnitSource) + else if (this.source is IUniTaskSource asyncUnitSource) { return new UniTask(asyncUnitSource, this.token); } @@ -440,7 +444,7 @@ namespace Cysharp.Threading.Tasks return self.AsUniTask(); } -#if !UNITY_2018_3_OR_NEWER +#if SUPPORT_VALUETASK public static implicit operator System.Threading.Tasks.ValueTask(in UniTask self) { @@ -449,7 +453,7 @@ namespace Cysharp.Threading.Tasks return new System.Threading.Tasks.ValueTask(self.result); } -#if NETSTANDARD2_0 +#if (UNITASK_NETCORE && NETSTANDARD2_0) return self.AsValueTask(); #else return new System.Threading.Tasks.ValueTask(self.source, self.token); diff --git a/UnityProject/Packages/UniTask/Runtime/UniTaskExtensions.cs b/UnityProject/Packages/UniTask/Runtime/UniTaskExtensions.cs index 362da525..1e4faa1e 100644 --- a/UnityProject/Packages/UniTask/Runtime/UniTaskExtensions.cs +++ b/UnityProject/Packages/UniTask/Runtime/UniTaskExtensions.cs @@ -454,7 +454,7 @@ namespace Cysharp.Threading.Tasks } /// - /// Timeout with suppress OperationCanceledException. Returns (bool, IsCacneled). + /// Timeout with suppress OperationCanceledException. Returns (bool, IsCanceled). /// public static async UniTask TimeoutWithoutException(this UniTask task, TimeSpan timeout, DelayType delayType = DelayType.DeltaTime, PlayerLoopTiming timeoutCheckTiming = PlayerLoopTiming.Update, CancellationTokenSource taskCancellationTokenSource = null) { diff --git a/UnityProject/Packages/UniTask/Runtime/UnityAsyncExtensions.AssetBundleRequestAllAssets.cs b/UnityProject/Packages/UniTask/Runtime/UnityAsyncExtensions.AssetBundleRequestAllAssets.cs index 5d34692d..043e1b8b 100644 --- a/UnityProject/Packages/UniTask/Runtime/UnityAsyncExtensions.AssetBundleRequestAllAssets.cs +++ b/UnityProject/Packages/UniTask/Runtime/UnityAsyncExtensions.AssetBundleRequestAllAssets.cs @@ -101,6 +101,7 @@ namespace Cysharp.Threading.Tasks IProgress progress; CancellationToken cancellationToken; CancellationTokenRegistration cancellationTokenRegistration; + bool cancelImmediately; bool completed; UniTaskCompletionSourceCore core; @@ -127,6 +128,7 @@ namespace Cysharp.Threading.Tasks result.asyncOperation = asyncOperation; result.progress = progress; result.cancellationToken = cancellationToken; + result.cancelImmediately = cancelImmediately; result.completed = false; asyncOperation.completed += result.continuationAction; @@ -156,7 +158,10 @@ namespace Cysharp.Threading.Tasks } finally { - TryReturn(); + if (!(cancelImmediately && cancellationToken.IsCancellationRequested)) + { + TryReturn(); + } } } @@ -216,6 +221,7 @@ namespace Cysharp.Threading.Tasks progress = default; cancellationToken = default; cancellationTokenRegistration.Dispose(); + cancelImmediately = default; return pool.TryPush(this); } @@ -223,19 +229,17 @@ namespace Cysharp.Threading.Tasks { if (completed) { - TryReturn(); + return; + } + + completed = true; + if (cancellationToken.IsCancellationRequested) + { + core.TrySetCanceled(cancellationToken); } else { - completed = true; - if (cancellationToken.IsCancellationRequested) - { - core.TrySetCanceled(cancellationToken); - } - else - { - core.TrySetResult(asyncOperation.allAssets); - } + core.TrySetResult(asyncOperation.allAssets); } } } diff --git a/UnityProject/Packages/UniTask/Runtime/UnityAsyncExtensions.AsyncGPUReadback.cs b/UnityProject/Packages/UniTask/Runtime/UnityAsyncExtensions.AsyncGPUReadback.cs index 5d73dc1a..a363be7a 100644 --- a/UnityProject/Packages/UniTask/Runtime/UnityAsyncExtensions.AsyncGPUReadback.cs +++ b/UnityProject/Packages/UniTask/Runtime/UnityAsyncExtensions.AsyncGPUReadback.cs @@ -45,7 +45,7 @@ namespace Cysharp.Threading.Tasks AsyncGPUReadbackRequest asyncOperation; CancellationToken cancellationToken; CancellationTokenRegistration cancellationTokenRegistration; - + bool cancelImmediately; UniTaskCompletionSourceCore core; AsyncGPUReadbackRequestAwaiterConfiguredSource() @@ -66,6 +66,7 @@ namespace Cysharp.Threading.Tasks result.asyncOperation = asyncOperation; result.cancellationToken = cancellationToken; + result.cancelImmediately = cancelImmediately; if (cancelImmediately && cancellationToken.CanBeCanceled) { @@ -92,7 +93,10 @@ namespace Cysharp.Threading.Tasks } finally { - TryReturn(); + if (!(cancelImmediately && cancellationToken.IsCancellationRequested)) + { + TryReturn(); + } } } @@ -146,6 +150,7 @@ namespace Cysharp.Threading.Tasks asyncOperation = default; cancellationToken = default; cancellationTokenRegistration.Dispose(); + cancelImmediately = default; return pool.TryPush(this); } } diff --git a/UnityProject/Packages/UniTask/Runtime/UnityAsyncExtensions.cs b/UnityProject/Packages/UniTask/Runtime/UnityAsyncExtensions.cs index b9cd1c9f..5a5ea1c1 100644 --- a/UnityProject/Packages/UniTask/Runtime/UnityAsyncExtensions.cs +++ b/UnityProject/Packages/UniTask/Runtime/UnityAsyncExtensions.cs @@ -97,6 +97,7 @@ namespace Cysharp.Threading.Tasks IProgress progress; CancellationToken cancellationToken; CancellationTokenRegistration cancellationTokenRegistration; + bool cancelImmediately; bool completed; UniTaskCompletionSourceCore core; @@ -123,6 +124,7 @@ namespace Cysharp.Threading.Tasks result.asyncOperation = asyncOperation; result.progress = progress; result.cancellationToken = cancellationToken; + result.cancelImmediately = cancelImmediately; result.completed = false; asyncOperation.completed += result.continuationAction; @@ -152,7 +154,10 @@ namespace Cysharp.Threading.Tasks } finally { - TryReturn(); + if (!(cancelImmediately && cancellationToken.IsCancellationRequested)) + { + TryReturn(); + } } } @@ -209,6 +214,7 @@ namespace Cysharp.Threading.Tasks progress = default; cancellationToken = default; cancellationTokenRegistration.Dispose(); + cancelImmediately = default; return pool.TryPush(this); } @@ -216,19 +222,16 @@ namespace Cysharp.Threading.Tasks { if (completed) { - TryReturn(); + return; + } + completed = true; + if (cancellationToken.IsCancellationRequested) + { + core.TrySetCanceled(cancellationToken); } else { - completed = true; - if (cancellationToken.IsCancellationRequested) - { - core.TrySetCanceled(cancellationToken); - } - else - { - core.TrySetResult(AsyncUnit.Default); - } + core.TrySetResult(AsyncUnit.Default); } } } @@ -320,6 +323,7 @@ namespace Cysharp.Threading.Tasks IProgress progress; CancellationToken cancellationToken; CancellationTokenRegistration cancellationTokenRegistration; + bool cancelImmediately; bool completed; UniTaskCompletionSourceCore core; @@ -346,6 +350,7 @@ namespace Cysharp.Threading.Tasks result.asyncOperation = asyncOperation; result.progress = progress; result.cancellationToken = cancellationToken; + result.cancelImmediately = cancelImmediately; result.completed = false; asyncOperation.completed += result.continuationAction; @@ -375,7 +380,10 @@ namespace Cysharp.Threading.Tasks } finally { - TryReturn(); + if (!(cancelImmediately && cancellationToken.IsCancellationRequested)) + { + TryReturn(); + } } } @@ -436,6 +444,7 @@ namespace Cysharp.Threading.Tasks progress = default; cancellationToken = default; cancellationTokenRegistration.Dispose(); + cancelImmediately = default; return pool.TryPush(this); } @@ -443,19 +452,16 @@ namespace Cysharp.Threading.Tasks { if (completed) { - TryReturn(); + return; + } + completed = true; + if (cancellationToken.IsCancellationRequested) + { + core.TrySetCanceled(cancellationToken); } else { - completed = true; - if (cancellationToken.IsCancellationRequested) - { - core.TrySetCanceled(cancellationToken); - } - else - { - core.TrySetResult(asyncOperation.asset); - } + core.TrySetResult(asyncOperation.asset); } } } @@ -548,6 +554,7 @@ namespace Cysharp.Threading.Tasks IProgress progress; CancellationToken cancellationToken; CancellationTokenRegistration cancellationTokenRegistration; + bool cancelImmediately; bool completed; UniTaskCompletionSourceCore core; @@ -574,6 +581,7 @@ namespace Cysharp.Threading.Tasks result.asyncOperation = asyncOperation; result.progress = progress; result.cancellationToken = cancellationToken; + result.cancelImmediately = cancelImmediately; result.completed = false; asyncOperation.completed += result.continuationAction; @@ -603,7 +611,10 @@ namespace Cysharp.Threading.Tasks } finally { - TryReturn(); + if (!(cancelImmediately && cancellationToken.IsCancellationRequested)) + { + TryReturn(); + } } } @@ -664,6 +675,7 @@ namespace Cysharp.Threading.Tasks progress = default; cancellationToken = default; cancellationTokenRegistration.Dispose(); + cancelImmediately = default; return pool.TryPush(this); } @@ -671,19 +683,16 @@ namespace Cysharp.Threading.Tasks { if (completed) { - TryReturn(); + return; + } + completed = true; + if (cancellationToken.IsCancellationRequested) + { + core.TrySetCanceled(cancellationToken); } else { - completed = true; - if (cancellationToken.IsCancellationRequested) - { - core.TrySetCanceled(cancellationToken); - } - else - { - core.TrySetResult(asyncOperation.asset); - } + core.TrySetResult(asyncOperation.asset); } } } @@ -777,6 +786,7 @@ namespace Cysharp.Threading.Tasks IProgress progress; CancellationToken cancellationToken; CancellationTokenRegistration cancellationTokenRegistration; + bool cancelImmediately; bool completed; UniTaskCompletionSourceCore core; @@ -803,6 +813,7 @@ namespace Cysharp.Threading.Tasks result.asyncOperation = asyncOperation; result.progress = progress; result.cancellationToken = cancellationToken; + result.cancelImmediately = cancelImmediately; result.completed = false; asyncOperation.completed += result.continuationAction; @@ -832,7 +843,10 @@ namespace Cysharp.Threading.Tasks } finally { - TryReturn(); + if (!(cancelImmediately && cancellationToken.IsCancellationRequested)) + { + TryReturn(); + } } } @@ -893,6 +907,7 @@ namespace Cysharp.Threading.Tasks progress = default; cancellationToken = default; cancellationTokenRegistration.Dispose(); + cancelImmediately = default; return pool.TryPush(this); } @@ -900,19 +915,16 @@ namespace Cysharp.Threading.Tasks { if (completed) { - TryReturn(); + return; + } + completed = true; + if (cancellationToken.IsCancellationRequested) + { + core.TrySetCanceled(cancellationToken); } else { - completed = true; - if (cancellationToken.IsCancellationRequested) - { - core.TrySetCanceled(cancellationToken); - } - else - { - core.TrySetResult(asyncOperation.assetBundle); - } + core.TrySetResult(asyncOperation.assetBundle); } } } @@ -1021,6 +1033,7 @@ namespace Cysharp.Threading.Tasks IProgress progress; CancellationToken cancellationToken; CancellationTokenRegistration cancellationTokenRegistration; + bool cancelImmediately; bool completed; UniTaskCompletionSourceCore core; @@ -1047,6 +1060,7 @@ namespace Cysharp.Threading.Tasks result.asyncOperation = asyncOperation; result.progress = progress; result.cancellationToken = cancellationToken; + result.cancelImmediately = cancelImmediately; result.completed = false; asyncOperation.completed += result.continuationAction; @@ -1077,7 +1091,10 @@ namespace Cysharp.Threading.Tasks } finally { - TryReturn(); + if (!(cancelImmediately && cancellationToken.IsCancellationRequested)) + { + TryReturn(); + } } } @@ -1146,6 +1163,7 @@ namespace Cysharp.Threading.Tasks progress = default; cancellationToken = default; cancellationTokenRegistration.Dispose(); + cancelImmediately = default; return pool.TryPush(this); } @@ -1153,23 +1171,20 @@ namespace Cysharp.Threading.Tasks { if (completed) { - TryReturn(); + return; + } + completed = true; + if (cancellationToken.IsCancellationRequested) + { + core.TrySetCanceled(cancellationToken); + } + else if (asyncOperation.webRequest.IsError()) + { + core.TrySetException(new UnityWebRequestException(asyncOperation.webRequest)); } else { - completed = true; - if (cancellationToken.IsCancellationRequested) - { - core.TrySetCanceled(cancellationToken); - } - else if (asyncOperation.webRequest.IsError()) - { - core.TrySetException(new UnityWebRequestException(asyncOperation.webRequest)); - } - else - { - core.TrySetResult(asyncOperation.webRequest); - } + core.TrySetResult(asyncOperation.webRequest); } } } diff --git a/UnityProject/Packages/UniTask/Runtime/UnityAsyncExtensions.tt b/UnityProject/Packages/UniTask/Runtime/UnityAsyncExtensions.tt index 0516fef1..e2437df0 100644 --- a/UnityProject/Packages/UniTask/Runtime/UnityAsyncExtensions.tt +++ b/UnityProject/Packages/UniTask/Runtime/UnityAsyncExtensions.tt @@ -165,6 +165,7 @@ namespace Cysharp.Threading.Tasks IProgress progress; CancellationToken cancellationToken; CancellationTokenRegistration cancellationTokenRegistration; + bool cancelImmediately; bool completed; UniTaskCompletionSourceCore<<#= IsVoid(t) ? "AsyncUnit" : t.returnType #>> core; @@ -191,6 +192,7 @@ namespace Cysharp.Threading.Tasks result.asyncOperation = asyncOperation; result.progress = progress; result.cancellationToken = cancellationToken; + result.cancelImmediately = cancelImmediately; result.completed = false; asyncOperation.completed += result.continuationAction; @@ -227,7 +229,10 @@ namespace Cysharp.Threading.Tasks } finally { - TryReturn(); + if (!(cancelImmediately && cancellationToken.IsCancellationRequested)) + { + TryReturn(); + } } } @@ -304,6 +309,7 @@ namespace Cysharp.Threading.Tasks progress = default; cancellationToken = default; cancellationTokenRegistration.Dispose(); + cancelImmediately = default; return pool.TryPush(this); } @@ -311,31 +317,28 @@ namespace Cysharp.Threading.Tasks { if (completed) { - TryReturn(); + return; + } + completed = true; + if (cancellationToken.IsCancellationRequested) + { + core.TrySetCanceled(cancellationToken); + } +<# if(IsUnityWebRequest(t)) { #> + else if (asyncOperation.webRequest.IsError()) + { + core.TrySetException(new UnityWebRequestException(asyncOperation.webRequest)); } else { - completed = true; - if (cancellationToken.IsCancellationRequested) - { - core.TrySetCanceled(cancellationToken); - } -<# if(IsUnityWebRequest(t)) { #> - else if (asyncOperation.webRequest.IsError()) - { - core.TrySetException(new UnityWebRequestException(asyncOperation.webRequest)); - } - else - { - core.TrySetResult(asyncOperation.webRequest); - } -<# } else { #> - else - { - core.TrySetResult(<#= IsVoid(t) ? "AsyncUnit.Default" : $"asyncOperation.{t.returnField}" #>); - } -<# } #> + core.TrySetResult(asyncOperation.webRequest); } +<# } else { #> + else + { + core.TrySetResult(<#= IsVoid(t) ? "AsyncUnit.Default" : $"asyncOperation.{t.returnField}" #>); + } +<# } #> } } diff --git a/UnityProject/Packages/UniTask/Runtime/_InternalVisibleTo.cs b/UnityProject/Packages/UniTask/Runtime/_InternalVisibleTo.cs index cd4db417..ab7c10c9 100644 --- a/UnityProject/Packages/UniTask/Runtime/_InternalVisibleTo.cs +++ b/UnityProject/Packages/UniTask/Runtime/_InternalVisibleTo.cs @@ -3,5 +3,4 @@ [assembly: InternalsVisibleTo("UniTask.Linq")] [assembly: InternalsVisibleTo("UniTask.Addressables")] [assembly: InternalsVisibleTo("UniTask.DOTween")] -[assembly: InternalsVisibleTo("UniTask.TextMeshPro")] -[assembly: InternalsVisibleTo("UniTask.YooAsset")] \ No newline at end of file +[assembly: InternalsVisibleTo("UniTask.TextMeshPro")] \ No newline at end of file diff --git a/UnityProject/Packages/UniTask/package.json b/UnityProject/Packages/UniTask/package.json index 84b5b0a3..488019cf 100644 --- a/UnityProject/Packages/UniTask/package.json +++ b/UnityProject/Packages/UniTask/package.json @@ -2,7 +2,7 @@ "name": "com.cysharp.unitask", "displayName": "UniTask", "author": { "name": "Cysharp, Inc.", "url": "https://cysharp.co.jp/en/" }, - "version": "2.5.0", + "version": "2.5.4", "unity": "2018.4", "description": "Provides an efficient async/await integration to Unity.", "keywords": [ "async/await", "async", "Task", "UniTask" ], diff --git a/UnityProject/Packages/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilderHelper.cs b/UnityProject/Packages/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilderHelper.cs index 45cd531b..b222318d 100644 --- a/UnityProject/Packages/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilderHelper.cs +++ b/UnityProject/Packages/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilderHelper.cs @@ -9,7 +9,7 @@ namespace YooAsset.Editor public static class AssetBundleBuilderHelper { /// - /// 获取默认的输出根路录 + /// 获取默认的输出根目录 /// public static string GetDefaultBuildOutputRoot() { diff --git a/UnityProject/Packages/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/BaseTasks/TaskCreateReport.cs b/UnityProject/Packages/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/BaseTasks/TaskCreateReport.cs index 56051f51..dccf6080 100644 --- a/UnityProject/Packages/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/BaseTasks/TaskCreateReport.cs +++ b/UnityProject/Packages/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/BaseTasks/TaskCreateReport.cs @@ -37,7 +37,7 @@ namespace YooAsset.Editor buildReport.Summary.EnableAddressable = buildMapContext.Command.EnableAddressable; buildReport.Summary.LocationToLower = buildMapContext.Command.LocationToLower; buildReport.Summary.IncludeAssetGUID = buildMapContext.Command.IncludeAssetGUID; - buildReport.Summary.IgnoreDefaultType = buildMapContext.Command.IgnoreDefaultType; + buildReport.Summary.IgnoreRuleName = buildMapContext.Command.IgnoreRule.GetType().FullName; buildReport.Summary.AutoCollectShaders = buildMapContext.Command.AutoCollectShaders; // 构建参数 diff --git a/UnityProject/Packages/YooAsset/Editor/AssetBundleBuilder/VisualViewers/BuiltinBuildPipelineViewer.cs b/UnityProject/Packages/YooAsset/Editor/AssetBundleBuilder/VisualViewers/BuiltinBuildPipelineViewer.cs index 60beadef..55fc367b 100644 --- a/UnityProject/Packages/YooAsset/Editor/AssetBundleBuilder/VisualViewers/BuiltinBuildPipelineViewer.cs +++ b/UnityProject/Packages/YooAsset/Editor/AssetBundleBuilder/VisualViewers/BuiltinBuildPipelineViewer.cs @@ -1,4 +1,4 @@ -#if UNITY_2019_4_OR_NEWER +#if UNITY_2019_4_OR_NEWER using System; using System.IO; using System.Linq; @@ -18,7 +18,7 @@ namespace YooAsset.Editor } /// - /// ִй + /// 执行构建 /// protected override void ExecuteBuild() { diff --git a/UnityProject/Packages/YooAsset/Editor/AssetBundleBuilder/VisualViewers/RawfileBuildpipelineViewer.cs b/UnityProject/Packages/YooAsset/Editor/AssetBundleBuilder/VisualViewers/RawfileBuildpipelineViewer.cs index c6dd0572..063869f3 100644 --- a/UnityProject/Packages/YooAsset/Editor/AssetBundleBuilder/VisualViewers/RawfileBuildpipelineViewer.cs +++ b/UnityProject/Packages/YooAsset/Editor/AssetBundleBuilder/VisualViewers/RawfileBuildpipelineViewer.cs @@ -1,4 +1,4 @@ -#if UNITY_2019_4_OR_NEWER +#if UNITY_2019_4_OR_NEWER using System; using System.IO; using System.Linq; @@ -20,7 +20,7 @@ namespace YooAsset.Editor } /// - /// ִй + /// 执行构建 /// protected override void ExecuteBuild() { diff --git a/UnityProject/Packages/YooAsset/Editor/AssetBundleCollector/AssetBundleCollector.cs b/UnityProject/Packages/YooAsset/Editor/AssetBundleCollector/AssetBundleCollector.cs index dbf96127..87374888 100644 --- a/UnityProject/Packages/YooAsset/Editor/AssetBundleCollector/AssetBundleCollector.cs +++ b/UnityProject/Packages/YooAsset/Editor/AssetBundleCollector/AssetBundleCollector.cs @@ -166,7 +166,7 @@ namespace YooAsset.Editor foreach (string assetPath in findAssets) { var assetInfo = new AssetInfo(assetPath); - if (IsValidateAsset(command, assetInfo) && IsCollectAsset(group, assetInfo)) + if (command.IgnoreRule.IsIgnore(assetInfo) == false && IsCollectAsset(group, assetInfo)) { if (result.ContainsKey(assetPath) == false) { @@ -228,37 +228,6 @@ namespace YooAsset.Editor return collectAssetInfo; } - private bool IsValidateAsset(CollectCommand command, AssetInfo assetInfo) - { - if (assetInfo.AssetPath.StartsWith("Assets/") == false && assetInfo.AssetPath.StartsWith("Packages/") == false) - { - UnityEngine.Debug.LogError($"Invalid asset path : {assetInfo.AssetPath}"); - return false; - } - - // 忽略文件夹 - if (AssetDatabase.IsValidFolder(assetInfo.AssetPath)) - return false; - - // 忽略编辑器下的类型资源 - if (assetInfo.AssetType == typeof(LightingDataAsset)) - return false; - - // 忽略Unity引擎无法识别的文件 - if (command.IgnoreDefaultType) - { - if (assetInfo.AssetType == typeof(UnityEditor.DefaultAsset)) - { - UnityEngine.Debug.LogWarning($"Cannot pack default asset : {assetInfo.AssetPath}"); - return false; - } - } - - if (DefaultFilterRule.IsIgnoreFile(assetInfo.FileExtension)) - return false; - - return true; - } private bool IsCollectAsset(AssetBundleCollectorGroup group, AssetInfo assetInfo) { // 根据规则设置过滤资源文件 @@ -312,7 +281,7 @@ namespace YooAsset.Editor continue; AssetInfo assetInfo = new AssetInfo(assetPath); - if (IsValidateAsset(command, assetInfo)) + if (command.IgnoreRule.IsIgnore(assetInfo) == false) result.Add(assetInfo); } return result; diff --git a/UnityProject/Packages/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorConfig.cs b/UnityProject/Packages/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorConfig.cs index 234286fe..24124104 100644 --- a/UnityProject/Packages/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorConfig.cs +++ b/UnityProject/Packages/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorConfig.cs @@ -10,7 +10,7 @@ namespace YooAsset.Editor { public class AssetBundleCollectorConfig { - public const string ConfigVersion = "v2.0.0"; + public const string ConfigVersion = "v2.1"; public const string XmlVersion = "Version"; public const string XmlCommon = "Common"; @@ -25,7 +25,7 @@ namespace YooAsset.Editor public const string XmlEnableAddressable = "AutoAddressable"; public const string XmlLocationToLower = "LocationToLower"; public const string XmlIncludeAssetGUID = "IncludeAssetGUID"; - public const string XmlIgnoreDefaultType = "IgnoreDefaultType"; + public const string XmlIgnoreRuleName = "IgnoreRuleName"; public const string XmlGroup = "Group"; public const string XmlGroupActiveRule = "GroupActiveRule"; @@ -101,7 +101,7 @@ namespace YooAsset.Editor package.EnableAddressable = packageElement.GetAttribute(XmlEnableAddressable) == "True" ? true : false; package.LocationToLower = packageElement.GetAttribute(XmlLocationToLower) == "True" ? true : false; package.IncludeAssetGUID = packageElement.GetAttribute(XmlIncludeAssetGUID) == "True" ? true : false; - package.IgnoreDefaultType = packageElement.GetAttribute(XmlIgnoreDefaultType) == "True" ? true : false; + package.IgnoreRuleName = packageElement.GetAttribute(XmlIgnoreRuleName); packages.Add(package); // 读取分组配置 @@ -213,7 +213,7 @@ namespace YooAsset.Editor packageElement.SetAttribute(XmlEnableAddressable, package.EnableAddressable.ToString()); packageElement.SetAttribute(XmlLocationToLower, package.LocationToLower.ToString()); packageElement.SetAttribute(XmlIncludeAssetGUID, package.IncludeAssetGUID.ToString()); - packageElement.SetAttribute(XmlIgnoreDefaultType, package.IgnoreDefaultType.ToString()); + packageElement.SetAttribute(XmlIgnoreRuleName, package.IgnoreRuleName); root.AppendChild(packageElement); // 设置分组配置 @@ -258,6 +258,23 @@ namespace YooAsset.Editor if (configVersion == ConfigVersion) return true; + // v2.0.0 -> v2.1 + if (configVersion == "v2.0.0") + { + // 读取包裹配置 + var packageNodeList = root.GetElementsByTagName(XmlPackage); + foreach (var packageNode in packageNodeList) + { + XmlElement packageElement = packageNode as XmlElement; + if (packageElement.HasAttribute(XmlIgnoreRuleName) == false) + packageElement.SetAttribute(XmlIgnoreRuleName, nameof(NormalIgnoreRule)); + } + + // 更新版本 + root.SetAttribute(XmlVersion, "v2.1"); + return UpdateXmlConfig(xmlDoc); + } + return false; } } diff --git a/UnityProject/Packages/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorPackage.cs b/UnityProject/Packages/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorPackage.cs index 702cfbab..4c8d7c84 100644 --- a/UnityProject/Packages/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorPackage.cs +++ b/UnityProject/Packages/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorPackage.cs @@ -35,16 +35,16 @@ namespace YooAsset.Editor /// public bool IncludeAssetGUID = false; - /// - /// 忽略Unity引擎无法识别的文件 - /// - public bool IgnoreDefaultType = true; - /// /// 自动收集所有着色器(所有着色器存储在一个资源包内) /// public bool AutoCollectShaders = true; + /// + /// 资源忽略规则名 + /// + public string IgnoreRuleName = nameof(NormalIgnoreRule); + /// /// 分组列表 /// @@ -56,6 +56,16 @@ namespace YooAsset.Editor /// public void CheckConfigError() { + if (string.IsNullOrEmpty(IgnoreRuleName)) + { + throw new Exception($"{nameof(IgnoreRuleName)} is null or empty !"); + } + else + { + if (AssetBundleCollectorSettingData.HasIgnoreRuleName(IgnoreRuleName) == false) + throw new Exception($"Invalid {nameof(IIgnoreRule)} class type : {IgnoreRuleName} in package : {PackageName}"); + } + foreach (var group in Groups) { group.CheckConfigError(); @@ -68,6 +78,14 @@ namespace YooAsset.Editor public bool FixConfigError() { bool isFixed = false; + + if (string.IsNullOrEmpty(IgnoreRuleName)) + { + Debug.LogWarning($"Set the {nameof(IgnoreRuleName)} to {nameof(NormalIgnoreRule)}"); + IgnoreRuleName = nameof(NormalIgnoreRule); + isFixed = true; + } + foreach (var group in Groups) { if (group.FixConfigError()) @@ -75,6 +93,7 @@ namespace YooAsset.Editor isFixed = true; } } + return isFixed; } diff --git a/UnityProject/Packages/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorSetting.cs b/UnityProject/Packages/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorSetting.cs index df00a1ed..2e468223 100644 --- a/UnityProject/Packages/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorSetting.cs +++ b/UnityProject/Packages/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorSetting.cs @@ -24,7 +24,6 @@ namespace YooAsset.Editor /// public bool UniqueBundleName = false; - /// /// 包裹列表 /// @@ -100,13 +99,13 @@ namespace YooAsset.Editor package.CheckConfigError(); // 创建资源收集命令 + IIgnoreRule ignoreRule = AssetBundleCollectorSettingData.GetIgnoreRuleInstance(package.IgnoreRuleName); CollectCommand command = new CollectCommand(buildMode, packageName, package.EnableAddressable, package.LocationToLower, package.IncludeAssetGUID, - package.IgnoreDefaultType, package.AutoCollectShaders, - UniqueBundleName); + UniqueBundleName, ignoreRule); // 获取收集的资源集合 CollectResult collectResult = new CollectResult(command); diff --git a/UnityProject/Packages/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorSettingData.cs b/UnityProject/Packages/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorSettingData.cs index ace3cfe1..c0c41a25 100644 --- a/UnityProject/Packages/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorSettingData.cs +++ b/UnityProject/Packages/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorSettingData.cs @@ -21,6 +21,9 @@ namespace YooAsset.Editor private static readonly Dictionary _cacheFilterRuleTypes = new Dictionary(); private static readonly Dictionary _cacheFilterRuleInstance = new Dictionary(); + private static readonly Dictionary _cacheIgnoreRuleTypes = new Dictionary(); + private static readonly Dictionary _cacheIgnoreRuleInstance = new Dictionary(); + /// /// 配置数据是否被修改 /// @@ -129,6 +132,29 @@ namespace YooAsset.Editor _cacheActiveRuleTypes.Add(type.Name, type); } } + + // IIgnoreRule + { + // 清空缓存集合 + _cacheIgnoreRuleTypes.Clear(); + _cacheIgnoreRuleInstance.Clear(); + + // 获取所有类型 + List types = new List(100) + { + typeof(NormalIgnoreRule), + typeof(RawFileIgnoreRule), + }; + + var customTypes = EditorTools.GetAssignableTypes(typeof(IIgnoreRule)); + types.AddRange(customTypes); + for (int i = 0; i < types.Count; i++) + { + Type type = types[i]; + if (_cacheIgnoreRuleTypes.ContainsKey(type.Name) == false) + _cacheIgnoreRuleTypes.Add(type.Name, type); + } + } } private static AssetBundleCollectorSetting _setting = null; @@ -165,6 +191,7 @@ namespace YooAsset.Editor if (isFixed) { IsDirty = true; + Debug.Log("Fix package config error done !"); } } @@ -225,6 +252,18 @@ namespace YooAsset.Editor } return names; } + public static List GetIgnoreRuleNames() + { + List names = new List(); + foreach (var pair in _cacheIgnoreRuleTypes) + { + RuleDisplayName ruleName = new RuleDisplayName(); + ruleName.ClassName = pair.Key; + ruleName.DisplayName = GetRuleDisplayName(pair.Key, pair.Value); + names.Add(ruleName); + } + return names; + } private static string GetRuleDisplayName(string name, Type type) { var attribute = DisplayNameAttributeHelper.GetAttribute(type); @@ -250,6 +289,10 @@ namespace YooAsset.Editor { return _cacheFilterRuleTypes.Keys.Contains(ruleName); } + public static bool HasIgnoreRuleName(string ruleName) + { + return _cacheIgnoreRuleTypes.Keys.Contains(ruleName); + } public static IActiveRule GetActiveRuleInstance(string ruleName) { @@ -319,6 +362,23 @@ namespace YooAsset.Editor throw new Exception($"{nameof(IFilterRule)} is invalid:{ruleName}"); } } + public static IIgnoreRule GetIgnoreRuleInstance(string ruleName) + { + if (_cacheIgnoreRuleInstance.TryGetValue(ruleName, out IIgnoreRule instance)) + return instance; + + // 如果不存在创建类的实例 + if (_cacheIgnoreRuleTypes.TryGetValue(ruleName, out Type type)) + { + instance = (IIgnoreRule)Activator.CreateInstance(type); + _cacheIgnoreRuleInstance.Add(ruleName, instance); + return instance; + } + else + { + throw new Exception($"{nameof(IIgnoreRule)} is invalid:{ruleName}"); + } + } // 公共参数编辑相关 public static void ModifyShowPackageView(bool showPackageView) diff --git a/UnityProject/Packages/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorWindow.cs b/UnityProject/Packages/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorWindow.cs index 0ce35519..f4691727 100644 --- a/UnityProject/Packages/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorWindow.cs +++ b/UnityProject/Packages/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorWindow.cs @@ -24,6 +24,7 @@ namespace YooAsset.Editor private List _addressRuleList; private List _packRuleList; private List _filterRuleList; + private List _ignoreRuleList; private VisualElement _helpBoxContainer; @@ -39,9 +40,9 @@ namespace YooAsset.Editor private Toggle _enableAddressableToogle; private Toggle _locationToLowerToogle; private Toggle _includeAssetGUIDToogle; - private Toggle _ignoreDefaultTypeToogle; private Toggle _autoCollectShadersToogle; - + private PopupField _ignoreRulePopupField; + private VisualElement _packageContainer; private ListView _packageListView; private TextField _packageNameTxt; @@ -77,6 +78,7 @@ namespace YooAsset.Editor _addressRuleList = AssetBundleCollectorSettingData.GetAddressRuleNames(); _packRuleList = AssetBundleCollectorSettingData.GetPackRuleNames(); _filterRuleList = AssetBundleCollectorSettingData.GetFilterRuleNames(); + _ignoreRuleList = AssetBundleCollectorSettingData.GetIgnoreRuleNames(); VisualElement root = this.rootVisualElement; @@ -151,17 +153,6 @@ namespace YooAsset.Editor RefreshWindow(); } }); - _ignoreDefaultTypeToogle = root.Q("IgnoreDefaultType"); - _ignoreDefaultTypeToogle.RegisterValueChangedCallback(evt => - { - var selectPackage = _packageListView.selectedItem as AssetBundleCollectorPackage; - if (selectPackage != null) - { - selectPackage.IgnoreDefaultType = evt.newValue; - AssetBundleCollectorSettingData.ModifyPackage(selectPackage); - RefreshWindow(); - } - }); _autoCollectShadersToogle = root.Q("AutoCollectShaders"); _autoCollectShadersToogle.RegisterValueChangedCallback(evt => { @@ -173,6 +164,25 @@ namespace YooAsset.Editor RefreshWindow(); } }); + { + _ignoreRulePopupField = new PopupField(_ignoreRuleList, 0); + _ignoreRulePopupField.label = "File Ignore Rule"; + _ignoreRulePopupField.name = "IgnoreRulePopupField"; + _ignoreRulePopupField.style.unityTextAlign = TextAnchor.MiddleLeft; + _ignoreRulePopupField.style.width = 300; + _ignoreRulePopupField.formatListItemCallback = FormatListItemCallback; + _ignoreRulePopupField.formatSelectedValueCallback = FormatSelectedValueCallback; + _ignoreRulePopupField.RegisterValueChangedCallback(evt => + { + var selectPackage = _packageListView.selectedItem as AssetBundleCollectorPackage; + if(selectPackage != null) + { + selectPackage.IgnoreRuleName = evt.newValue.ClassName; + AssetBundleCollectorSettingData.ModifyPackage(selectPackage); + } + }); + _setting2Container.Add(_ignoreRulePopupField); + } // 配置修复按钮 var fixBtn = root.Q