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 255d1e9d5a..f5fe59be66 100644 Binary files a/UnityProject/Assets/TEngine/Runtime/Core/GameEvent/GameEventAnalyzer.dll and b/UnityProject/Assets/TEngine/Runtime/Core/GameEvent/GameEventAnalyzer.dll differ diff --git a/UnityProject/Assets/TEngine/Runtime/Core/GameEvent/SourceGenerator.dll b/UnityProject/Assets/TEngine/Runtime/Core/GameEvent/SourceGenerator.dll index 2a10e16cf4..d75e641257 100644 Binary files a/UnityProject/Assets/TEngine/Runtime/Core/GameEvent/SourceGenerator.dll and b/UnityProject/Assets/TEngine/Runtime/Core/GameEvent/SourceGenerator.dll differ diff --git a/UnityProject/Assets/TEngine/Runtime/Module/ResourceModule/Extension/Implement/SetSpriteExtensions.cs b/UnityProject/Assets/TEngine/Runtime/Module/ResourceModule/Extension/Implement/SetSpriteExtensions.cs index a64eadfb7d..48fe342f64 100644 --- a/UnityProject/Assets/TEngine/Runtime/Module/ResourceModule/Extension/Implement/SetSpriteExtensions.cs +++ b/UnityProject/Assets/TEngine/Runtime/Module/ResourceModule/Extension/Implement/SetSpriteExtensions.cs @@ -17,6 +17,10 @@ public static class SetSpriteExtensions /// 取消设置资源的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; }