feat(events): 添加全局事件获取或添加功能

- 实现了GetOrAdd方法用于获取或添加指定类型的全局事件
- 添加了XML文档注释说明方法用途和泛型约束
- 方法支持自动创建不存在的事件实例并返回指定类型对象
This commit is contained in:
GeWuYou 2026-01-15 22:00:32 +08:00
parent 2ae26ea590
commit 6cfde41dc6

View File

@ -1,4 +1,4 @@
using GFramework.Core.Abstractions.events;
using GFramework.Core.Abstractions.events;
namespace GFramework.Core.events;
@ -37,6 +37,16 @@ public class EasyEvents
MGlobalEvents.AddEvent<T>();
}
/// <summary>
/// 获取或添加指定类型的全局事件
/// </summary>
/// <typeparam name="T">事件类型必须实现IEasyEvent接口且具有无参构造函数</typeparam>
/// <returns>指定类型的事件实例</returns>
public static T GetOrAdd<T>() where T : IEvent, new()
{
return MGlobalEvents.GetOrAddEvent<T>();
}
/// <summary>
/// 添加指定类型的事件到事件字典中
/// </summary>