mirror of
https://github.com/GeWuYou/GFramework.git
synced 2026-03-22 10:34:30 +08:00
- 新增 Architecture 基类与 IArchitecture 接口,实现单例模式与组件注册管理 - 集成 IOC 容器支持系统、模型、工具的依赖注入与生命周期管理 - 实现命令模式基础类 AbstractCommand 与接口 ICommand,支持带返回值命令 - 提供事件系统集成,支持事件的发布与订阅机制 - 添加控制器接口 IController,整合命令发送、事件注册与模型获取能力 - 创建详细的 README 文档说明各组件使用方式与设计模式应用 - 支持命令、查询、事件的统一调度与解耦通信机制
32 lines
938 B
C#
32 lines
938 B
C#
namespace GFramework.framework.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();
|
|
}
|