Game Events
by
Facepunch
| Summary | Strongly 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 Rate | 0% |
| 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 | {} |
| Version | Created | Size (modified) | Files | Changes |
|---|---|---|---|---|
| 65480 | 156.8 KB (142.3 KB) | 19 +3 ~9 -9 | Changes on 2024-08-11 | |
| 64781 | 209.9 KB (141.6 KB) | 25 ~7 | Changes on 2024-08-08 | |
| 64761 | 209.5 KB (147.6 KB) | 25 ~8 | Changes on 2024-08-08 | |
| 64727 | 207.5 KB (198.5 KB) | 25 +19 ~1 -4 | Changes on 2024-08-08 | |
| 60139 | 28.8 KB (5.5 KB) | 10 ~1 | Changes on 2024-07-11 | |
| 60137 | 28.9 KB (10.1 KB) | 10 ~2 | Changes on 2024-07-11 | |
| 60121 | 28.2 KB (5.9 KB) | 10 ~3 | Changes on 2024-07-11 | |
| 58385 | 28.5 KB (5.2 KB) | 10 ~1 | Changes on 2024-06-13 | |
| 58380 | 28.2 KB (13.8 KB) | 10 ~3 | Changes on 2024-06-13 | |
| 58357 | 27.9 KB (4.4 KB) | 10 ~1 | Changes on 2024-06-12 | |
| 58356 | 27.3 KB (4.6 KB) | 10 ~1 | Changes on 2024-06-12 | |
| 58355 | 26.8 KB (8.2 KB) | 10 ~2 | Changes on 2024-06-12 | |
| 58323 | 26.2 KB (5.3 KB) | 10 ~2 | Changes on 2024-06-11 | |
| 58308 | 25.2 KB | 10 +10 | Changes on 2024-06-11 |
Loading history…