using System; using AlicizaX.Runtime; using Cysharp.Threading.Tasks; namespace AlicizaX.EventKit.Runtime { public class EventProcessorAttribute : Attribute { public EventProcessorAttribute() { } } public interface IEventProcessor { /// /// /// /// Type EventType(); /// /// /// /// UniTask Invoke(object self); } public abstract class EventProcessorHandler : IEventProcessor where T : unmanaged, IEvent { private readonly Type _selfType = typeof(T); /// /// /// /// public Type EventType() { return _selfType; } /// /// 事件调用的方法,要在这个方法里编写事件发生的逻辑 /// /// protected abstract UniTask Handler(T self); /// /// /// /// public async UniTask Invoke(object self) { try { await Handler((T)self); } catch (Exception e) { Log.Error($"{_selfType.Name} Error {e}"); } } } }