GwWuYou 82713e34f0 refactor(core): 重构架构和命令相关代码结构
- 调整了 Architecture 类中字段和方法的布局,提升可读性
- 优化了命令执行逻辑,明确区分有无返回值的命令处理
- 规范了接口和抽象类的注释格式,增强文档清晰度
- 统一了代码风格,对齐缩进与换行符使用
- 补充了事件系统中泛型事件类的功能实现
- 完善了 README 文档中的条目结构和内容表述
2025-12-12 21:10:21 +08:00

56 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.extensions;
namespace GFramework.Core.events;
/// <summary>
/// OrEvent类用于实现事件的或逻辑组合当任意一个注册的事件触发时都会触发OrEvent本身
/// </summary>
public class OrEvent : IUnRegisterList
{
private Action _mOnEvent = () => { };
/// <summary>
/// 获取取消注册列表
/// </summary>
public List<IUnRegister> UnregisterList { get; } = new();
/// <summary>
/// 将指定的事件与当前OrEvent进行或逻辑组合
/// </summary>
/// <param name="easyEvent">要组合的事件对象</param>
/// <returns>返回当前OrEvent实例支持链式调用</returns>
public OrEvent Or(IEasyEvent easyEvent)
{
easyEvent.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();
}
}