diff --git a/GFramework.Core.Abstractions/architecture/IArchitectureServices.cs b/GFramework.Core.Abstractions/architecture/IArchitectureServices.cs index 66b9eb9..efdb88e 100644 --- a/GFramework.Core.Abstractions/architecture/IArchitectureServices.cs +++ b/GFramework.Core.Abstractions/architecture/IArchitectureServices.cs @@ -21,7 +21,7 @@ public interface IArchitectureServices : IContextAware /// 获取类型事件系统 /// /// ITypeEventSystem类型的事件系统实例 - ITypeEventSystem TypeEventSystem { get; } + IEventBus EventBus { get; } /// /// 获取命令总线 diff --git a/GFramework.Core.Abstractions/events/IEasyEvent.cs b/GFramework.Core.Abstractions/events/IEvent.cs similarity index 93% rename from GFramework.Core.Abstractions/events/IEasyEvent.cs rename to GFramework.Core.Abstractions/events/IEvent.cs index c83a7e0..ef66913 100644 --- a/GFramework.Core.Abstractions/events/IEasyEvent.cs +++ b/GFramework.Core.Abstractions/events/IEvent.cs @@ -5,7 +5,7 @@ namespace GFramework.Core.Abstractions.events; /// /// 事件接口,定义了事件注册的基本功能 /// -public interface IEasyEvent +public interface IEvent { /// /// 注册事件处理函数 diff --git a/GFramework.Core.Abstractions/events/ITypeEventSystem.cs b/GFramework.Core.Abstractions/events/IEventBus.cs similarity index 89% rename from GFramework.Core.Abstractions/events/ITypeEventSystem.cs rename to GFramework.Core.Abstractions/events/IEventBus.cs index 014b6ef..acf94f1 100644 --- a/GFramework.Core.Abstractions/events/ITypeEventSystem.cs +++ b/GFramework.Core.Abstractions/events/IEventBus.cs @@ -3,9 +3,9 @@ namespace GFramework.Core.Abstractions.events; /// -/// 类型事件系统接口,定义基于类型的事件发送、注册和注销功能 +/// 事件总线接口,提供事件的发送、注册和注销功能 /// -public interface ITypeEventSystem +public interface IEventBus { /// /// 发送事件,自动创建事件实例 diff --git a/GFramework.Core.Abstractions/property/IReadonlyBindableProperty.cs b/GFramework.Core.Abstractions/property/IReadonlyBindableProperty.cs index 78ee0cf..e4d86a8 100644 --- a/GFramework.Core.Abstractions/property/IReadonlyBindableProperty.cs +++ b/GFramework.Core.Abstractions/property/IReadonlyBindableProperty.cs @@ -7,7 +7,7 @@ namespace GFramework.Core.Abstractions.property; /// 只读可绑定属性接口,提供属性值的读取和变更监听功能 /// /// 属性值的类型 -public interface IReadonlyBindableProperty : IEasyEvent +public interface IReadonlyBindableProperty : IEvent { /// /// 获取属性的当前值 diff --git a/GFramework.Core/architecture/Architecture.cs b/GFramework.Core/architecture/Architecture.cs index 7cf2b92..13e709b 100644 --- a/GFramework.Core/architecture/Architecture.cs +++ b/GFramework.Core/architecture/Architecture.cs @@ -61,13 +61,7 @@ public abstract class Architecture( /// private IIocContainer Container => Services.Container; - /// - /// 获取类型事件系统 - /// - /// - /// 通过Services属性获取的IArchitectureServices中的TypeEventSystem属性 - /// - private ITypeEventSystem TypeEventSystem => Services.TypeEventSystem; + private IEventBus EventBus => Services.EventBus; private ICommandBus CommandBus => Services.CommandBus; @@ -226,7 +220,7 @@ public abstract class Architecture( // 进入销毁阶段并发送销毁开始事件 _logger.Info("Starting architecture destruction"); EnterPhase(ArchitecturePhase.Destroying); - TypeEventSystem.Send(new ArchitectureEvents.ArchitectureDestroyingEvent()); + EventBus.Send(new ArchitectureEvents.ArchitectureDestroyingEvent()); // 销毁所有系统组件并清空系统列表 _logger.Info($"Destroying {_allSystems.Count} systems"); @@ -240,7 +234,7 @@ public abstract class Architecture( // 进入已销毁阶段并发送销毁完成事件 EnterPhase(ArchitecturePhase.Destroyed); - TypeEventSystem.Send(new ArchitectureEvents.ArchitectureDestroyedEvent()); + EventBus.Send(new ArchitectureEvents.ArchitectureDestroyedEvent()); _logger.Info("Architecture destruction completed"); } @@ -262,7 +256,7 @@ public abstract class Architecture( _logger.Error("Architecture initialization failed:", e); EnterPhase(ArchitecturePhase.FailedInitialization); // 发送初始化失败事件 - TypeEventSystem.Send(new ArchitectureEvents.ArchitectureFailedInitializationEvent()); + EventBus.Send(new ArchitectureEvents.ArchitectureFailedInitializationEvent()); } } @@ -281,7 +275,7 @@ public abstract class Architecture( _logger.Error("Architecture initialization failed:", e); EnterPhase(ArchitecturePhase.FailedInitialization); // 发送初始化失败事件 - TypeEventSystem.Send(new ArchitectureEvents.ArchitectureFailedInitializationEvent()); + EventBus.Send(new ArchitectureEvents.ArchitectureFailedInitializationEvent()); } } @@ -322,7 +316,7 @@ public abstract class Architecture( _logger = LoggerFactoryResolver.Provider.CreateLogger(GetType().Name); Environment.Initialize(); // 初始化架构上下文(如果尚未初始化) - _context ??= new ArchitectureContext(Container, TypeEventSystem, CommandBus, QueryBus, Environment); + _context ??= new ArchitectureContext(Container, EventBus, CommandBus, QueryBus, Environment); // 将当前架构类型与上下文绑定到游戏上下文 GameContext.Bind(GetType(), _context); @@ -387,7 +381,7 @@ public abstract class Architecture( _mInitialized = true; EnterPhase(ArchitecturePhase.Ready); - TypeEventSystem.Send(new ArchitectureEvents.ArchitectureLifecycleReadyEvent()); + EventBus.Send(new ArchitectureEvents.ArchitectureLifecycleReadyEvent()); _logger.Info($"Architecture {GetType().Name} is ready - all components initialized"); } diff --git a/GFramework.Core/architecture/ArchitectureContext.cs b/GFramework.Core/architecture/ArchitectureContext.cs index d5dfbf2..a394717 100644 --- a/GFramework.Core/architecture/ArchitectureContext.cs +++ b/GFramework.Core/architecture/ArchitectureContext.cs @@ -15,7 +15,7 @@ namespace GFramework.Core.architecture; /// public class ArchitectureContext( IIocContainer container, - ITypeEventSystem typeEventSystem, + IEventBus eventBus, ICommandBus commandBus, IQueryBus queryBus, IEnvironment environment) @@ -25,10 +25,11 @@ public class ArchitectureContext( private readonly IIocContainer _container = container ?? throw new ArgumentNullException(nameof(container)); private readonly IEnvironment _environment = environment ?? throw new ArgumentNullException(nameof(environment)); - private readonly IQueryBus _queryBus = queryBus ?? throw new ArgumentNullException(nameof(queryBus)); - private readonly ITypeEventSystem _typeEventSystem = - typeEventSystem ?? throw new ArgumentNullException(nameof(typeEventSystem)); + private readonly IEventBus _eventBus = + eventBus ?? throw new ArgumentNullException(nameof(eventBus)); + + private readonly IQueryBus _queryBus = queryBus ?? throw new ArgumentNullException(nameof(queryBus)); #region Query Execution @@ -113,7 +114,7 @@ public class ArchitectureContext( /// 事件类型 public void SendEvent() where TEvent : new() { - _typeEventSystem.Send(); + _eventBus.Send(); } /// @@ -124,7 +125,7 @@ public class ArchitectureContext( public void SendEvent(TEvent e) where TEvent : class { ArgumentNullException.ThrowIfNull(e); - _typeEventSystem.Send(e); + _eventBus.Send(e); } /// @@ -135,7 +136,7 @@ public class ArchitectureContext( /// 事件注销接口 public IUnRegister RegisterEvent(Action handler) { - return handler == null ? throw new ArgumentNullException(nameof(handler)) : _typeEventSystem.Register(handler); + return handler == null ? throw new ArgumentNullException(nameof(handler)) : _eventBus.Register(handler); } /// @@ -146,7 +147,7 @@ public class ArchitectureContext( public void UnRegisterEvent(Action onEvent) { ArgumentNullException.ThrowIfNull(onEvent); - _typeEventSystem.UnRegister(onEvent); + _eventBus.UnRegister(onEvent); } /// diff --git a/GFramework.Core/architecture/ArchitectureServices.cs b/GFramework.Core/architecture/ArchitectureServices.cs index 3ee3406..d79bd18 100644 --- a/GFramework.Core/architecture/ArchitectureServices.cs +++ b/GFramework.Core/architecture/ArchitectureServices.cs @@ -25,7 +25,7 @@ public class ArchitectureServices : IArchitectureServices /// /// 获取类型事件系统 /// - public ITypeEventSystem TypeEventSystem { get; } = new TypeEventSystem(); + public IEventBus EventBus { get; } = new EventBus(); /// /// 获取命令总线 diff --git a/GFramework.Core/events/EasyEventGeneric.cs b/GFramework.Core/events/EasyEventGeneric.cs index 8d673e2..ede45ba 100644 --- a/GFramework.Core/events/EasyEventGeneric.cs +++ b/GFramework.Core/events/EasyEventGeneric.cs @@ -4,10 +4,10 @@ namespace GFramework.Core.events; /// /// 泛型事件类,支持一个泛型参数 T 的事件注册、注销与触发。 -/// 实现了 IEasyEvent 接口以提供统一的事件操作接口。 +/// 实现了 IEvent 接口以提供统一的事件操作接口。 /// /// 事件回调函数的第一个参数类型。 -public class EasyEvent : IEasyEvent +public class Event : IEvent { /// /// 存储已注册的事件处理委托。 @@ -16,12 +16,12 @@ public class EasyEvent : IEasyEvent private Action? _mOnEvent = _ => { }; /// - /// 显式实现 IEasyEvent 接口中的 Register 方法。 + /// 显式实现 IEvent 接口中的 Register 方法。 /// 允许使用无参 Action 来订阅当前带参事件。 /// /// 无参事件处理方法。 /// IUnRegister 对象,用于稍后注销该事件监听器。 - IUnRegister IEasyEvent.Register(Action onEvent) + IUnRegister IEvent.Register(Action onEvent) { return Register(Action); @@ -67,7 +67,7 @@ public class EasyEvent : IEasyEvent /// /// 第一个参数类型。 /// 第二个参数类型。 -public class EasyEvent : IEasyEvent +public class Event : IEvent { /// /// 存储已注册的双参数事件处理委托。 @@ -76,12 +76,12 @@ public class EasyEvent : IEasyEvent private Action? _mOnEvent = (_, _) => { }; /// - /// 显式实现 IEasyEvent 接口中的 Register 方法。 + /// 显式实现 IEvent 接口中的 Register 方法。 /// 允许使用无参 Action 来订阅当前带参事件。 /// /// 无参事件处理方法。 /// IUnRegister 对象,用于稍后注销该事件监听器。 - IUnRegister IEasyEvent.Register(Action onEvent) + IUnRegister IEvent.Register(Action onEvent) { return Register(Action); diff --git a/GFramework.Core/events/EasyEvents.cs b/GFramework.Core/events/EasyEvents.cs index 19c03e7..6943320 100644 --- a/GFramework.Core/events/EasyEvents.cs +++ b/GFramework.Core/events/EasyEvents.cs @@ -16,14 +16,14 @@ public class EasyEvents /// /// 存储事件类型与事件实例映射关系的字典 /// - private readonly Dictionary _mTypeEvents = new(); + private readonly Dictionary _mTypeEvents = new(); /// /// 获取指定类型的全局事件实例 /// /// 事件类型,必须实现IEasyEvent接口 /// 指定类型的事件实例,如果未注册则返回默认值 - public static T Get() where T : IEasyEvent + public static T Get() where T : IEvent { return MGlobalEvents.GetEvent(); } @@ -32,7 +32,7 @@ public class EasyEvents /// 注册指定类型的全局事件 /// /// 事件类型,必须实现IEasyEvent接口且具有无参构造函数 - public static void Register() where T : IEasyEvent, new() + public static void Register() where T : IEvent, new() { MGlobalEvents.AddEvent(); } @@ -41,7 +41,7 @@ public class EasyEvents /// 添加指定类型的事件到事件字典中 /// /// 事件类型,必须实现IEasyEvent接口且具有无参构造函数 - public void AddEvent() where T : IEasyEvent, new() + public void AddEvent() where T : IEvent, new() { _mTypeEvents.Add(typeof(T), new T()); } @@ -51,7 +51,7 @@ public class EasyEvents /// /// 事件类型,必须实现IEasyEvent接口 /// 指定类型的事件实例,如果不存在则返回默认值 - public T GetEvent() where T : IEasyEvent + public T GetEvent() where T : IEvent { return _mTypeEvents.TryGetValue(typeof(T), out var e) ? (T)e : default!; } @@ -61,7 +61,7 @@ public class EasyEvents /// /// 事件类型,必须实现IEasyEvent接口且具有无参构造函数 /// 指定类型的事件实例 - public T GetOrAddEvent() where T : IEasyEvent, new() + public T GetOrAddEvent() where T : IEvent, new() { var eType = typeof(T); // 尝试从字典中获取事件实例 diff --git a/GFramework.Core/events/TypeEventSystem.cs b/GFramework.Core/events/EventBus.cs similarity index 83% rename from GFramework.Core/events/TypeEventSystem.cs rename to GFramework.Core/events/EventBus.cs index 3659406..f4fef72 100644 --- a/GFramework.Core/events/TypeEventSystem.cs +++ b/GFramework.Core/events/EventBus.cs @@ -5,7 +5,7 @@ namespace GFramework.Core.events; /// /// 类型事件系统,提供基于类型的事件发送、注册和注销功能 /// -public class TypeEventSystem : ITypeEventSystem +public class EventBus : IEventBus { private readonly EasyEvents _mEvents = new(); @@ -16,7 +16,7 @@ public class TypeEventSystem : ITypeEventSystem public void Send() where T : new() { _mEvents - .GetOrAddEvent>() + .GetOrAddEvent>() .Trigger(new T()); } @@ -28,7 +28,7 @@ public class TypeEventSystem : ITypeEventSystem public void Send(T e) { _mEvents - .GetOrAddEvent>() + .GetOrAddEvent>() .Trigger(e); } @@ -40,7 +40,7 @@ public class TypeEventSystem : ITypeEventSystem /// 反注册接口,用于注销事件监听 public IUnRegister Register(Action onEvent) { - return _mEvents.GetOrAddEvent>().Register(onEvent); + return _mEvents.GetOrAddEvent>().Register(onEvent); } /// @@ -50,6 +50,6 @@ public class TypeEventSystem : ITypeEventSystem /// 要注销的事件处理回调函数 public void UnRegister(Action onEvent) { - _mEvents.GetEvent>().UnRegister(onEvent); + _mEvents.GetEvent>().UnRegister(onEvent); } } \ No newline at end of file diff --git a/GFramework.Core/events/OrEvent.cs b/GFramework.Core/events/OrEvent.cs index 896cf26..1f79e63 100644 --- a/GFramework.Core/events/OrEvent.cs +++ b/GFramework.Core/events/OrEvent.cs @@ -18,11 +18,11 @@ public class OrEvent : IUnRegisterList /// /// 将指定的事件与当前OrEvent进行或逻辑组合 /// - /// 要组合的事件对象 + /// 要组合的事件对象 /// 返回当前OrEvent实例,支持链式调用 - public OrEvent Or(IEasyEvent easyEvent) + public OrEvent Or(IEvent @event) { - easyEvent.Register(Trigger).AddToUnregisterList(this); + @event.Register(Trigger).AddToUnregisterList(this); return this; } diff --git a/GFramework.Core/extensions/OrEventExtensions.cs b/GFramework.Core/extensions/OrEventExtensions.cs index 96ddb04..261ebeb 100644 --- a/GFramework.Core/extensions/OrEventExtensions.cs +++ b/GFramework.Core/extensions/OrEventExtensions.cs @@ -14,7 +14,7 @@ public static class OrEventExtensions /// 当前的IEasyEvent事件实例 /// 要与当前事件进行或运算的另一个IEasyEvent事件实例 /// 返回一个新的OrEvent实例,表示两个事件的或运算结果 - public static OrEvent Or(this IEasyEvent self, IEasyEvent e) + public static OrEvent Or(this IEvent self, IEvent e) { return new OrEvent().Or(self).Or(e); } diff --git a/GFramework.Core/property/BindableProperty.cs b/GFramework.Core/property/BindableProperty.cs index c91e41e..9c720f3 100644 --- a/GFramework.Core/property/BindableProperty.cs +++ b/GFramework.Core/property/BindableProperty.cs @@ -54,7 +54,7 @@ public class BindableProperty(T defaultValue = default!) : IBindableProperty< /// /// 无参事件回调 /// 可用于取消注册的接口 - IUnRegister IEasyEvent.Register(Action onEvent) + IUnRegister IEvent.Register(Action onEvent) { return Register(Action);