GwWuYou 157b3ce846 refactor(events): 将类型事件系统重构为事件总线
- 将TypeEventSystem重命名为EventBus
- 将IEasyEvent接口重命名为IEvent接口
- 将ITypeEventSystem接口重命名为IEventBus接口
- 更新Architecture类中使用TypeEventSystem为EventBus
- 更新ArchitectureContext中依赖注入参数类型
- 将EasyEvent泛型类重命名为Event泛型类
- 更新所有相关类型引用和实现
- 修改接口继承关系以使用新的事件接口命名
2026-01-11 11:17:30 +08:00

57 lines
1.6 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using GFramework.Core.Abstractions.events;
using GFramework.Core.extensions;
namespace GFramework.Core.events;
/// <summary>
/// OrEvent类用于实现事件的或逻辑组合当任意一个注册的事件触发时都会触发OrEvent本身
/// </summary>
public class OrEvent : IUnRegisterList
{
private Action? _mOnEvent = () => { };
/// <summary>
/// 获取取消注册列表
/// </summary>
public IList<IUnRegister> UnregisterList { get; } = new List<IUnRegister>();
/// <summary>
/// 将指定的事件与当前OrEvent进行或逻辑组合
/// </summary>
/// <param name="event">要组合的事件对象</param>
/// <returns>返回当前OrEvent实例支持链式调用</returns>
public OrEvent Or(IEvent @event)
{
@event.Register(Trigger).AddToUnregisterList(this);
return this;
}
/// <summary>
/// 注册事件处理函数
/// </summary>
/// <param name="onEvent">要注册的事件处理函数</param>
/// <returns>返回一个可取消注册的对象</returns>
public IUnRegister Register(Action onEvent)
{
_mOnEvent += onEvent;
return new DefaultUnRegister(() => { UnRegister(onEvent); });
}
/// <summary>
/// 取消注册指定的事件处理函数
/// </summary>
/// <param name="onEvent">要取消注册的事件处理函数</param>
public void UnRegister(Action onEvent)
{
_mOnEvent -= onEvent;
this.UnRegisterAll();
}
/// <summary>
/// 触发所有已注册的事件处理函数
/// </summary>
private void Trigger()
{
_mOnEvent?.Invoke();
}
}