-
Notifications
You must be signed in to change notification settings - Fork 36
EventBus
genar edited this page Apr 28, 2023
·
2 revisions
To decouple code and outsource logic using events, Arch.Extended
has the EventBus. The special feature here, it is completely source generated and therefore as fast as native method calls. And it can even be inlined and supports static classes and instances.
public partial class MyInstanceReceiver {
public MysInstanceReceiver(){ Hook(); } // To start listening.
[Event(order...)]
public void OnShootEvent(ref ShootEvent @event){
// Handle
}
... Other event receiving methods
}
public static class SomeEventHandler{
[Event(order: ...)]
public static void OnShootFireBullets(ref ShootEvent event){ // ref, none, in supported and all types as a event. Only one param!
// Do stuff
}
...
}
var shootEvent = ...;
EventBus.Send(ref shootEvent); // Broadcasts the event to all annotated static methods wherever they are.