From 5a1b01ea20ac7c2d558c35b83dadd6a55f88c5ac Mon Sep 17 00:00:00 2001 From: Pavel Shevaev Date: Wed, 21 May 2025 19:43:53 +0300 Subject: [PATCH] Adding UnitTask support via USE_UNITASK compile define --- tpl/codegen_services.twig | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/tpl/codegen_services.twig b/tpl/codegen_services.twig index 963472b..ea471c5 100644 --- a/tpl/codegen_services.twig +++ b/tpl/codegen_services.twig @@ -4,6 +4,9 @@ using System.Threading.Tasks; using System.Collections.Generic; using metagen; using BitGames.Bits; +#if USE_UNITASK +using Cysharp.Threading.Tasks; +#endif {%- for use in uses ~%} using {{use}}; {%- endfor ~%} @@ -16,7 +19,12 @@ namespace {{namespace}} public interface IRpcCaller { - Task CallRpc(metagen.IRpc rpc); +#if USE_UNITASK + UniTask +#else + Task +#endif + CallRpc(metagen.IRpc rpc); } public interface IApiBase @@ -26,7 +34,15 @@ public interface IApiBase public interface IRpcCallBuilder where TRpc : metagen.IRpc { - public Task Call(); + public + +#if USE_UNITASK + UniTask +#else + Task +#endif + + Call(); } public struct RpcCallBuilder : IRpcCallBuilder where TRpc : IRpc @@ -40,7 +56,13 @@ public struct RpcCallBuilder : IRpcCallBuilder where TRpc : IRpc this.rpc = rpc; } - public async Task Call() + public async +#if USE_UNITASK + UniTask +#else + Task +#endif + Call() { await clt.CallRpc(rpc); return rpc; @@ -56,10 +78,17 @@ public struct MockRpcCallBuilder : IRpcCallBuilder where TRpc : IRpc this.Rpc = rpc; } +#if USE_UNITASK + public UniTask Call() + { + return UniTask.FromResult(Rpc); + } +#else public Task Call() { return Task.FromResult(Rpc); } +#endif } {%- for unit in meta.units %}