mirror of
https://github.com/GeWuYou/GFramework.git
synced 2026-03-23 03:04:29 +08:00
- 调整了 Architecture 类中字段和方法的布局,提升可读性 - 优化了命令执行逻辑,明确区分有无返回值的命令处理 - 规范了接口和抽象类的注释格式,增强文档清晰度 - 统一了代码风格,对齐缩进与换行符使用 - 补充了事件系统中泛型事件类的功能实现 - 完善了 README 文档中的条目结构和内容表述
37 lines
982 B
C#
37 lines
982 B
C#
namespace GFramework.Core.events;
|
|
|
|
/// <summary>
|
|
/// 简单事件类,用于注册、注销和触发无参事件回调
|
|
/// </summary>
|
|
public class EasyEvent
|
|
{
|
|
private Action _mOnEvent = () => { };
|
|
|
|
/// <summary>
|
|
/// 注册事件回调函数
|
|
/// </summary>
|
|
/// <param name="onEvent">要注册的事件回调函数</param>
|
|
/// <returns>用于注销事件的 unregister 对象</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;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 触发所有已注册的事件回调函数
|
|
/// </summary>
|
|
public void Trigger()
|
|
{
|
|
_mOnEvent?.Invoke();
|
|
}
|
|
} |