The event system is like the Hook system in Garry's Mod. It allows you to register functions on classes to receive a callback on certain global events.
Setting up your Class
Entities and panels are automatically registered/unregistered for you - for everything else, you just need to call
Registering a Callback
[Event.*] attribute will add it to the list to be called.
The various events called from the engine currently:
Called clientside every frame to process input and encode outputs into a user command.
Called when a client disconnects.
Called when a client joins.
Called just before the beginning of a rendering frame.
Called every server or client tick (60 times a second by default).
Called before each physics step, this is usually every tick but can be more depending on PhysicsSubSteps.
Called after each physics step.
Called each time your C# is hotloaded after successful recompile.
Post Entity Spawn
Called after all map entities have spawned in, including after map cleanups.
You can register your own custom event callbacks and call them.
Events can pass up to three arguments too.
If you want, you can also make your own custom EventAttributes (like
[Event.Tick]) and use them to register handlers. The behavior is the same as raw event names but they have all the benefits of a type (picked up by IntelliSense, checked at compile time, etc.)
Defining Method Arguments
When using custom event attributes you can define the required method arguments. This way, any methods that listen for this event must have matching arguments.