From 559506ddc5184f95a7fb309dd4f87a91641fe18d Mon Sep 17 00:00:00 2001 From: Amani <799375868@qq.com> Date: Sun, 13 Sep 2026 11:20:16 +0800 Subject: [PATCH] =?UTF-8?q?EventCenter=E6=94=B9=E5=90=8D=E4=B8=BAGameEvent?= =?UTF-8?q?Helper=E7=AC=A6=E5=90=88=E9=A1=B9=E7=9B=AE=E5=91=BD=E5=90=8D?= =?UTF-8?q?=E4=B9=A0=E6=83=AF=EF=BC=8CSetSprite=E6=8F=90=E5=89=8D=E5=81=9A?= =?UTF-8?q?=E8=B5=84=E6=BA=90=E5=9C=B0=E5=9D=80=E7=9A=84=E5=88=A4=E7=A9=BA?= =?UTF-8?q?=E8=BF=94=E5=9B=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1、GameEventAnalyzer增加RemoveEventListener的检查 2、EventCenter重命名为GameEventHelper 3、SetSpriteExtensions的SetSprite提前对资源地址进行判空返回,防止进入资源模块的异常抛出 4、ResourceExtComponent.Resource取消对异步取消的警告日志 --- .../GameEventAnalyzer/Definition.cs | 2 +- .../Generator/EventInterfaceGenerator.cs | 44 +++++++++--------- .../Core/GameEvent/GameEventAnalyzer.dll | Bin 25600 -> 25600 bytes .../Core/GameEvent/SourceGenerator.dll | Bin 27136 -> 27136 bytes .../Implement/SetSpriteExtensions.cs | 16 +++++++ .../ResourceExtComponent.Resource.cs | 4 ++ 6 files changed, 43 insertions(+), 23 deletions(-) diff --git a/Tools/GameEventSourceGenerator/GameEventAnalyzer/Definition.cs b/Tools/GameEventSourceGenerator/GameEventAnalyzer/Definition.cs index b969108685..c41609577f 100644 --- a/Tools/GameEventSourceGenerator/GameEventAnalyzer/Definition.cs +++ b/Tools/GameEventSourceGenerator/GameEventAnalyzer/Definition.cs @@ -78,7 +78,7 @@ public sealed class Definition /// public static readonly List CheckMethodNameList = [ - "AddUIEvent", "AddEventListener" + "AddUIEvent", "AddEventListener", "RemoveEventListener" ]; /// diff --git a/Tools/GameEventSourceGenerator/SourceGenerator/Generator/EventInterfaceGenerator.cs b/Tools/GameEventSourceGenerator/SourceGenerator/Generator/EventInterfaceGenerator.cs index a190a8c248..3ad3fbd853 100644 --- a/Tools/GameEventSourceGenerator/SourceGenerator/Generator/EventInterfaceGenerator.cs +++ b/Tools/GameEventSourceGenerator/SourceGenerator/Generator/EventInterfaceGenerator.cs @@ -9,15 +9,15 @@ [Generator] public class EventInterfaceGenerator : ISourceGenerator { - private sealed class EventCenterInterfaceInfo + private sealed class GameEventHelperInterfaceInfo { public string InterfaceName { get; set; } = string.Empty; public string EventClassName { get; set; } = string.Empty; public string GroupClassName { get; set; } = string.Empty; - public List Methods { get; } = new List(); + public List Methods { get; } = new List(); } - private sealed class EventCenterMethodInfo + private sealed class GameEventHelperMethodInfo { public string MethodName { get; set; } = string.Empty; public string ActionType { get; set; } = string.Empty; @@ -31,7 +31,7 @@ public void Execute(GeneratorExecutionContext context) { var syntaxTrees = context.Compilation.SyntaxTrees; List classNameList = new List(); - List eventCenterInterfaceInfos = new List(); + List gameEventHelperInterfaceInfos = new List(); foreach (var tree in syntaxTrees) { @@ -61,15 +61,15 @@ public void Execute(GeneratorExecutionContext context) context.AddSource($"{interfaceName}_Gen.g.cs", implementationClassCode); classNameList.Add($"{interfaceName}_Gen"); - eventCenterInterfaceInfos.Add(GenerateEventCenterInterfaceInfo(interfaceName, eventClassName, interfaceNode, context)); + gameEventHelperInterfaceInfos.Add(GenerateGameEventHelperInterfaceInfo(interfaceName, eventClassName, interfaceNode, context)); } } if (classNameList.Count > 0) { - string uniqueFileName = $"GameEventHelper.g.cs"; + string uniqueFileName = $"GameEventHelper.Init.g.cs"; context.AddSource(uniqueFileName, GenerateGameEventHelper(classNameList)); - context.AddSource("EventCenter.g.cs", GenerateEventCenter(eventCenterInterfaceInfos)); + context.AddSource("GameEventHelper.g.cs", GenerateGameEventHelper(gameEventHelperInterfaceInfos)); } } @@ -90,7 +90,7 @@ private string GenerateGameEventHelper(List classNameList) sb.AppendLine(); sb.AppendLine($"namespace {Definition.NameSpace}"); sb.AppendLine($"{{"); - sb.AppendLine($" public static class GameEventHelper"); + sb.AppendLine($" public static partial class GameEventHelper"); sb.AppendLine(" {"); sb.AppendLine($" public static void Init()"); sb.AppendLine(" {"); @@ -106,7 +106,7 @@ private string GenerateGameEventHelper(List classNameList) return sb.ToString(); } - private string GenerateEventCenter(List eventCenterInterfaceInfos) + private string GenerateGameEventHelper(List gameEventHelperInterfaceInfos) { var sb = new StringBuilder(); sb.AppendLine($"//------------------------------------------------------------------------------"); @@ -123,24 +123,24 @@ private string GenerateEventCenter(List eventCenterInt sb.AppendLine(); sb.AppendLine($"namespace {Definition.NameSpace}"); sb.AppendLine($"{{"); - sb.AppendLine($" public partial class EventCenter"); + sb.AppendLine($" public static partial class GameEventHelper"); sb.AppendLine(" {"); - GenerateEventCenterGroup(sb, eventCenterInterfaceInfos, "AddEvent", "AddEventListener"); + GenerateGameEventHelperGroup(sb, gameEventHelperInterfaceInfos, "AddEvent", "AddEventListener"); sb.AppendLine(); - GenerateEventCenterGroup(sb, eventCenterInterfaceInfos, "RemoveEvent", "RemoveEventListener"); + GenerateGameEventHelperGroup(sb, gameEventHelperInterfaceInfos, "RemoveEvent", "RemoveEventListener"); sb.AppendLine(" }"); sb.AppendLine("}"); return sb.ToString(); } - private void GenerateEventCenterGroup(StringBuilder sb, List eventCenterInterfaceInfos, string className, string methodName) + private void GenerateGameEventHelperGroup(StringBuilder sb, List gameEventHelperInterfaceInfos, string className, string methodName) { sb.AppendLine($" public partial class {className}"); sb.AppendLine(" {"); - for (int i = 0; i < eventCenterInterfaceInfos.Count; i++) + for (int i = 0; i < gameEventHelperInterfaceInfos.Count; i++) { - var interfaceInfo = eventCenterInterfaceInfos[i]; + var interfaceInfo = gameEventHelperInterfaceInfos[i]; sb.AppendLine($" public partial class {interfaceInfo.GroupClassName}"); sb.AppendLine(" {"); @@ -160,7 +160,7 @@ private void GenerateEventCenterGroup(StringBuilder sb, List()) { - eventCenterInterfaceInfo.Methods.Add(new EventCenterMethodInfo + gameEventHelperInterfaceInfo.Methods.Add(new GameEventHelperMethodInfo { MethodName = method.Identifier.ToString(), ActionType = GenerateActionType(method, semanticModel), }); } - return eventCenterInterfaceInfo; + return gameEventHelperInterfaceInfo; } - private string GetEventCenterGroupName(string interfaceName) + private string GetGameEventHelperGroupName(string interfaceName) { if (interfaceName.Length > 1 && interfaceName[0] == 'I' && char.IsUpper(interfaceName[1])) { diff --git a/UnityProject/Assets/TEngine/Runtime/Core/GameEvent/GameEventAnalyzer.dll b/UnityProject/Assets/TEngine/Runtime/Core/GameEvent/GameEventAnalyzer.dll index 255d1e9d5a68fe9eeb7143168689d64813cea1d1..f5fe59be66b7eeea76ac1664ea4cb843aced3a34 100644 GIT binary patch delta 1411 zcmZXUZERCj7{~wT(sjKPMz`VCtt7MUUQ5^Y^|k|FG6QaltTbp{oSoRUTbyx>j4{-H z=w`(zE`fOw1~Eut5Q$L(H<~oT;9}I7m}v-~oD!CqNCIZY7vd-4bI(1x5^r;!dw%Et zKj%5mY3`X?U{ee1=xe5pjhB9!o!QKOpFQ8lPOFSHm(0BcJgzzGELVFa z3;uLdlu&|84+1}K1DJYYAfm;kjETLkeqv6=>h?bZlr@f@XV^E^#k-f+y31=_SrUe+ z3cyq&rrG}+t)fx48ZUjp-mZ`J(o&vrQ@JT#O>HbjINmO)E2WVl{l5R{VaucJ0d?B) zGsR)~hQE{6a*y}$*vDgv$59@$JRail2#+VVTv=j$%{c-oyOp+d$J_{*_n+4DpVMwu zzhz+sb-MmuR?tq=Cs^&b65vWahG)Ehl@80*mFU?{?|oW{V~Zu1q1nK3Ja0ybp%@`>f zP} z>D9NRP^9@Ve;0itoL;KlhucJy-$)U_9U*$C!T>yqz8Ry65Tf@Rq*oC_w;;WWFgDSb z_iqtlI5`{FCemnF5?8Ss?k7?Fxt?noC7h^l;wC{sTbm2YidhGKuZ*(}54yOD*C6EaP zBAIj~=ui8jVP85G>KIC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O&@zJ})9qJrYW($eO-#=3^w;=H2friOxslA?m9oZOQ9oczM#=0cRe81n$hyJnnT z3uJO7-h{9QzwP+1u=cwC4zUXm|IdNnboRR(zxC!_b;+&`k01MTeP_#^U3F_Nov120 zZ~nCI(cvLsa(zh1d>@KgD0_~QOWxq@&U#$m|5;|取消设置资源的Token。 public static void SetSprite(this Image image, string location, bool setNativeSize = false, Action callback = null, CancellationToken cancellationToken = default) { + if (string.IsNullOrEmpty(location)) + { + return; + } ResourceExtComponent.Instance.SetAssetByResources(SetSpriteObject.Create(image, location, setNativeSize, callback, cancellationToken), cancellationToken).Forget(); } @@ -29,6 +33,10 @@ public static void SetSprite(this Image image, string location, bool setNativeSi /// 取消设置资源的Token。 public static void SetSprite(this SpriteRenderer spriteRenderer, string location, Action callback = null, CancellationToken cancellationToken = default) { + if (string.IsNullOrEmpty(location)) + { + return; + } ResourceExtComponent.Instance.SetAssetByResources(SetSpriteObject.Create(spriteRenderer, location, callback, cancellationToken), cancellationToken).Forget(); } @@ -42,6 +50,10 @@ public static void SetSprite(this SpriteRenderer spriteRenderer, string location /// 取消设置资源的Token。 public static void SetSubSprite(this Image image, string location, string spriteName, bool setNativeSize = false, CancellationToken cancellationToken = default) { + if (string.IsNullOrEmpty(location) || string.IsNullOrEmpty(spriteName)) + { + return; + } ResourceExtComponent.Instance.SetSubSprite(image, location, spriteName, setNativeSize, cancellationToken).Forget(); } @@ -54,6 +66,10 @@ public static void SetSubSprite(this Image image, string location, string sprite /// 取消设置资源的Token。 public static void SetSubSprite(this SpriteRenderer spriteRenderer, string location, string spriteName, CancellationToken cancellationToken = default) { + if (string.IsNullOrEmpty(location) || string.IsNullOrEmpty(spriteName)) + { + return; + } ResourceExtComponent.Instance.SetSubSprite(spriteRenderer, location, spriteName, cancellationToken).Forget(); } } \ No newline at end of file diff --git a/UnityProject/Assets/TEngine/Runtime/Module/ResourceModule/Extension/ResourceExtComponent.Resource.cs b/UnityProject/Assets/TEngine/Runtime/Module/ResourceModule/Extension/ResourceExtComponent.Resource.cs index e04da45416..be76907e25 100644 --- a/UnityProject/Assets/TEngine/Runtime/Module/ResourceModule/Extension/ResourceExtComponent.Resource.cs +++ b/UnityProject/Assets/TEngine/Runtime/Module/ResourceModule/Extension/ResourceExtComponent.Resource.cs @@ -107,6 +107,10 @@ public async UniTaskVoid SetAssetByResources(ISetAssetObject setAssetObject, loadedResource = await _resourceModule.LoadAssetAsync(location, linkedTokenSource.Token); if (loadedResource == null) { + if (linkedTokenSource.IsCancellationRequested) + { + return; + } Log.Error("加载资源失败,资源为空: '{0}'", location); return; }