mirror of
https://github.com/GeWuYou/GFramework.git
synced 2026-03-22 10:34:30 +08:00
- 将所有小写的命名空间导入更正为首字母大写格式 - 统一 GFramework 框架的命名空间引用规范 - 修复 core、ecs、godot 等模块的命名空间导入错误 - 标准化文档示例代码中的 using 语句格式 - 确保所有文档中的命名空间引用保持一致性 - 更新 global using 语句以匹配正确的命名空间格式
57 lines
1.6 KiB
C#
57 lines
1.6 KiB
C#
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();
|
||
}
|
||
} |