From aa4f15d01b7ab3cda233d2f44037672468f62543 Mon Sep 17 00:00:00 2001 From: Tesmi <88522894+Tesmi-Develop@users.noreply.github.com> Date: Sat, 9 May 2026 21:02:08 +1000 Subject: [PATCH] feat: added global events --- src/Hypercube.Ecs/Events/IEventBus.cs | 12 ++++++++++++ src/Hypercube.Ecs/System/EntitySystem.World.cs | 16 ++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/src/Hypercube.Ecs/Events/IEventBus.cs b/src/Hypercube.Ecs/Events/IEventBus.cs index 240dcfc..f9e5ba1 100644 --- a/src/Hypercube.Ecs/Events/IEventBus.cs +++ b/src/Hypercube.Ecs/Events/IEventBus.cs @@ -12,6 +12,12 @@ void Subscribe(Handling.EventHandler han void Unsubscribe(Handling.EventHandler handler) where TComponent : IComponent where TEvent : struct, IEvent; + + void Subscribe(Handling.EventHandler handler, int priority = EventHandlerList.NoPriority) + where TEvent : struct, IEvent; + + void Unsubscribe(Handling.EventHandler handler) + where TEvent : struct, IEvent; void Raise(Entity entity, ref TComponent component, TEvent args) where TComponent : IComponent @@ -20,4 +26,10 @@ void Raise(Entity entity, ref TComponent component, TEvent a void Raise(Entity entity, ref TComponent component, ref TEvent args) where TComponent : IComponent where TEvent : struct, IEvent; + + void Raise(TEvent args) + where TEvent : struct, IEvent; + + void Raise(ref TEvent args) + where TEvent : struct, IEvent; } diff --git a/src/Hypercube.Ecs/System/EntitySystem.World.cs b/src/Hypercube.Ecs/System/EntitySystem.World.cs index 269a479..3a4b0c9 100644 --- a/src/Hypercube.Ecs/System/EntitySystem.World.cs +++ b/src/Hypercube.Ecs/System/EntitySystem.World.cs @@ -74,4 +74,20 @@ protected void Raise(Entity entity, ref TComponent component where TComponent : IComponent where TEvent : struct, IEvent => World.Events.Raise(entity, ref component, ref args); + + protected void Subscribe(Events.Handling.EventHandler handler, int priority = EventHandlerList.NoPriority) + where TEvent : struct, IEvent + => World.Events.Subscribe(handler, priority); + + protected void Unsubscribe(Events.Handling.EventHandler handler) + where TEvent : struct, IEvent + => World.Events.Unsubscribe(handler); + + protected void Raise(TEvent args) + where TEvent : struct, IEvent + => World.Events.Raise(ref args); + + protected void Raise(ref TEvent args) + where TEvent : struct, IEvent + => World.Events.Raise(ref args); }