using GFramework.Core.Abstractions.events; namespace GFramework.Core.events; /// /// 类型事件系统,提供基于类型的事件发送、注册和注销功能 /// public class EventBus : IEventBus { private readonly EasyEvents _mEvents = new(); /// /// 发送事件,自动创建事件实例 /// /// 事件类型,必须具有无参构造函数 public void Send() where T : new() { _mEvents .GetOrAddEvent>() .Trigger(new T()); } /// /// 发送指定的事件实例 /// /// 事件类型 /// 事件实例 public void Send(T e) { _mEvents .GetOrAddEvent>() .Trigger(e); } /// /// 注册事件监听器 /// /// 事件类型 /// 事件处理回调函数 /// 反注册接口,用于注销事件监听 public IUnRegister Register(Action onEvent) { return _mEvents.GetOrAddEvent>().Register(onEvent); } /// /// 注销事件监听器 /// /// 事件类型 /// 要注销的事件处理回调函数 public void UnRegister(Action onEvent) { _mEvents.GetEvent>().UnRegister(onEvent); } }