using System; using System.Buffers; using System.Collections.Generic; using System.Reflection; using System.Runtime.CompilerServices; using Cysharp.Threading.Tasks; namespace AlicizaX.EventKit.Runtime { public class EventPublisher : IDisposable { private readonly Dictionary> _asyncEvents = new Dictionary>(); public EventPublisher() { // EventKit.Publisher.Subscribe(OnLoad); } // // internal void OnLoad(SystemAssemblyLoadEventData assemblies) // { // HashSet types = SystemTypeCollector.Instance.GetTypes(typeof(EventProcessorAttribute)); // // foreach (var type in types) // { // var @event = (IEventProcessor)Activator.CreateInstance(type); // // if (@event == null) // { // continue; // } // // var eventType = @event.EventType(); // if (!_asyncEvents.ContainsKey(eventType)) _asyncEvents.Add(eventType, new List()); // _asyncEvents[@eventType].Add(@event); // } // } // // /// // /// 异步发布一个值类型的事件数据。 // /// // /// 事件数据类型(值类型)。 // /// 事件数据实例。 // /// 表示异步操作的任务。 // public async UniTaskVoid PublishAsync(TEventData eventData) where TEventData : struct // { // if (!_asyncEvents.TryGetValue(typeof(TEventData), out var list)) // { // return; // } // // var tasks = ListPool.Get(); // foreach (var @event in list) // { // tasks.Add(@event.Invoke(eventData)); // } // // await UniTask.WhenAll(tasks); // ListPool.Release(tasks); // } void IDisposable.Dispose() { _asyncEvents.Clear(); } } }