using System; using System.Collections.Generic; using System.Reflection; using Cysharp.Threading.Tasks; namespace ShrinkEventBus { public interface IShrinkEventSubscription : IDisposable { long SubscriptionId { get; } bool IsDisposed { get; } } public readonly struct ShrinkEventSubscriptionSnapshot { public ShrinkEventSubscriptionSnapshot(long subscriptionId, Type eventType, EventPriority priority, int numericPriority, bool receiveCanceled, object target, string targetTypeName, string methodName, string debugInfo, DateTime registeredAtUtc) { SubscriptionId = subscriptionId; EventType = eventType ?? throw new ArgumentNullException(nameof(eventType)); Priority = priority; NumericPriority = numericPriority; ReceiveCanceled = receiveCanceled; Target = target; TargetTypeName = targetTypeName ?? string.Empty; MethodName = methodName ?? string.Empty; DebugInfo = debugInfo ?? string.Empty; RegisteredAtUtc = registeredAtUtc; } public long SubscriptionId { get; } public Type EventType { get; } public EventPriority Priority { get; } public int NumericPriority { get; } public bool ReceiveCanceled { get; } public object Target { get; } public string TargetTypeName { get; } public string MethodName { get; } public string DebugInfo { get; } public DateTime RegisteredAtUtc { get; } public bool IsStaticHandler => Target == null; } public interface IShrinkEventBus { event Action OnEventTriggered; #if UNITY_EDITOR event Action OnEventTriggeredForEditor; bool EnableDebugRecord { get; set; } #endif bool IsStarted { get; } void Start(); void AutoRegister(object target); void Register(object target); void Unregister(object target); void RegisterEvent(Action handler, EventPriority priority = EventPriority.NORMAL, bool receiveCanceled = false) where TEvent : EventBase; void RegisterEvent(Action handler, int priority) where TEvent : EventBase; void RegisterEvent(Func handler, EventPriority priority = EventPriority.NORMAL, bool receiveCanceled = false) where TEvent : EventBase; void RegisterEvent(Func handler, int priority) where TEvent : EventBase; IShrinkEventSubscription SubscribeEvent(Action handler, EventPriority priority = EventPriority.NORMAL, bool receiveCanceled = false) where TEvent : EventBase; IShrinkEventSubscription SubscribeEvent(Action handler, int priority) where TEvent : EventBase; IShrinkEventSubscription SubscribeEvent(Func handler, EventPriority priority = EventPriority.NORMAL, bool receiveCanceled = false) where TEvent : EventBase; IShrinkEventSubscription SubscribeEvent(Func handler, int priority) where TEvent : EventBase; void UnregisterEvent(Action handler) where TEvent : EventBase; void UnregisterEvent(Func handler) where TEvent : EventBase; void ClearAllSubscribersForEvent() where TEvent : EventBase; void UnregisterAllEventsForObject(object targetObject); void UnregisterAllEvents(); bool TriggerEvent(TEvent eventArgs) where TEvent : EventBase; bool TriggerEvent(EventPriority phase, TEvent eventArgs) where TEvent : EventBase; UniTask TriggerEventAsync(TEvent eventArgs) where TEvent : EventBase; UniTask TriggerEventAsync(EventPriority phase, TEvent eventArgs) where TEvent : EventBase; EventHandlerInfo[] GetEventSubscribers() where TEvent : EventBase; ListenerList GetListenerList() where TEvent : EventBase; IReadOnlyDictionary GetAllSubscribersSnapshot(); IReadOnlyList GetActiveSubscriptionsSnapshot(); bool IsInstanceRegistered(object target); int GetRegisteredInstanceCount(); int GetRegisteredEventTypeCount(); } public interface IShrinkEventExceptionHandler { void HandleException(IShrinkEventBus bus, EventBase eventArgs, EventHandlerInfo[] listeners, int index, Exception exception); } public enum ShrinkEventExceptionHandlingMode { LogAndContinue, Throw, LogAndThrow } }