库

s&box 库列表

Game Events

facepunch.libevents

Strongly typed game events

关于

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<DamagedEvent>
{
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<SomeOtherComponent>]
public void OnGameEvent( DamagedEvent eventArgs )
{
Log.Info( $"{eventArgs.Victim.Name} says \"Ouch!\"" );
}

更多作品,作者: Facepunch

查看创作团队分析 →
05
Spline Tools 缩略图
Spline Toolsfacepunch.splinetools

Work In Progress Spline Tools.

+024小时
12收藏
17好评
86%Terry 评分
06
Model Viewer 缩略图
Model Viewerfacepunch.modelviewer

No summary provided.

+024小时
9收藏
9好评
77%Terry 评分