From ad23f7fb29b8c706dd8acc1b7858cdd4968ce7b4 Mon Sep 17 00:00:00 2001 From: hadashiA Date: Thu, 2 Nov 2023 12:52:24 +0900 Subject: [PATCH] Fix `#if` directive that should be in .tt --- .../Plugins/UniTask/Runtime/UnityAsyncExtensions.cs | 3 +++ .../Plugins/UniTask/Runtime/UnityAsyncExtensions.tt | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/src/UniTask/Assets/Plugins/UniTask/Runtime/UnityAsyncExtensions.cs b/src/UniTask/Assets/Plugins/UniTask/Runtime/UnityAsyncExtensions.cs index 7d86361..b9cd1c9 100644 --- a/src/UniTask/Assets/Plugins/UniTask/Runtime/UnityAsyncExtensions.cs +++ b/src/UniTask/Assets/Plugins/UniTask/Runtime/UnityAsyncExtensions.cs @@ -15,11 +15,14 @@ namespace Cysharp.Threading.Tasks { #region AsyncOperation +#if !UNITY_2023_1_OR_NEWER + // from Unity2023.1.0a15, AsyncOperationAwaitableExtensions.GetAwaiter is defined in UnityEngine. public static AsyncOperationAwaiter GetAwaiter(this AsyncOperation asyncOperation) { Error.ThrowArgumentNullException(asyncOperation, nameof(asyncOperation)); return new AsyncOperationAwaiter(asyncOperation); } +#endif public static UniTask WithCancellation(this AsyncOperation asyncOperation, CancellationToken cancellationToken) { diff --git a/src/UniTask/Assets/Plugins/UniTask/Runtime/UnityAsyncExtensions.tt b/src/UniTask/Assets/Plugins/UniTask/Runtime/UnityAsyncExtensions.tt index 6c6ff91..0516fef 100644 --- a/src/UniTask/Assets/Plugins/UniTask/Runtime/UnityAsyncExtensions.tt +++ b/src/UniTask/Assets/Plugins/UniTask/Runtime/UnityAsyncExtensions.tt @@ -16,6 +16,7 @@ Func ToUniTaskReturnType = x => (x == "void") ? "UniTask" : $"UniTask<{x}>"; Func ToIUniTaskSourceReturnType = x => (x == "void") ? "IUniTaskSource" : $"IUniTaskSource<{x}>"; + Func<(string typeName, string returnType, string returnField), bool> IsAsyncOperationBase = x => x.typeName == "AsyncOperation"; Func<(string typeName, string returnType, string returnField), bool> IsUnityWebRequest = x => x.returnType == "UnityWebRequest"; Func<(string typeName, string returnType, string returnField), bool> IsAssetBundleModule = x => x.typeName == "AssetBundleRequest" || x.typeName == "AssetBundleCreateRequest"; Func<(string typeName, string returnType, string returnField), bool> IsVoid = x => x.returnType == "void"; @@ -43,11 +44,18 @@ namespace Cysharp.Threading.Tasks <# } #> #region <#= t.typeName #> +<# if (IsAsyncOperationBase(t)) { #> +#if !UNITY_2023_1_OR_NEWER + // from Unity2023.1.0a15, AsyncOperationAwaitableExtensions.GetAwaiter is defined in UnityEngine. +<# } #> public static <#= t.typeName #>Awaiter GetAwaiter(this <#= t.typeName #> asyncOperation) { Error.ThrowArgumentNullException(asyncOperation, nameof(asyncOperation)); return new <#= t.typeName #>Awaiter(asyncOperation); } +<# if (IsAsyncOperationBase(t)) { #> +#endif +<# } #> public static <#= ToUniTaskReturnType(t.returnType) #> WithCancellation(this <#= t.typeName #> asyncOperation, CancellationToken cancellationToken) {