Game Events

thumb
Identfacepunch.libevents
Typelibrary
Created
Updated
Latest Version 65480 142.3 KB +3 ~9 -9
Tags event events fsm
Links s&box
SummaryStrongly typed game events
Description
About Game Events Easily dispatch events in your scene when stuff happens. Basics Declare an event type implementing with all the properties you want to pass around. public record DamagedEvent( GameObject Attacker, GameObject Victim, int Damage ) : IGameEvent; Implement for your custom event type in a . public sealed class MyComponent : Component, IGameEventHandler { public void OnGameEvent( DamagedEvent eventArgs ) { Log.Info( $"{eventArgs.Victim.Name} says \"Ouch!\"" ); } } Dispatch the event on a or the , which will notify any components in its descendants. GameObject.Dispatch( new DamagedEvent( attacker, victim, 50 ) ); Invocation order You can control the order that handlers are invoked using attributes on the handler method. * : run this first * : run this last * : run this before 's handler * : run this after 's handler [Early, After] public void OnGameEvent( DamagedEvent eventArgs ) { Log.Info( $"{eventArgs.Victim.Name} says \"Ouch!\"" ); }
About Game Events Easily dispatch events in your scene when stuff happens. Basics Declare an event type implementing with all the properties you want to pass around. public record DamagedEvent( GameObject Attacker, GameObject Victim, int Damage ) : IGameEvent; Implement for your custom event type in a . public sealed class MyComponent : Component, IGameEventHandler { public void OnGameEvent( DamagedEvent eventArgs ) { Log.Info( $"{eventArgs.Victim.Name} says \"Ouch!\"" ); } } Dispatch the event on a or the , which will notify any components in its descendants. GameObject.Dispatch( new DamagedEvent( attacker, victim, 50 ) ); Invocation order You can control the order that handlers are invoked using attributes on the handler method. * : run this first * : run this last * : run this before 's handler * : run this after 's handler [Early, After] public void OnGameEvent( DamagedEvent eventArgs ) { Log.Info( $"{eventArgs.Victim.Name} says \"Ouch!\"" ); }
Votes 13 0 15
Error Rate0%
Reviews
1 reviews
100% Recommended (1) 0% Promise (0) 0% Needs Work (0)
Usage
556 players 1,383 sessions 73 hours playtime 3 minutes avg session
Totals captured
Data
{}