Skip to content

Commit

Permalink
Examples: update AddSignalHandler() example
Browse files Browse the repository at this point in the history
  • Loading branch information
friflo committed Jan 8, 2025
1 parent 76933d7 commit f856c94
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/Tests/ECS/Examples/General.cs
Original file line number Diff line number Diff line change
Expand Up @@ -247,15 +247,22 @@ public static void TagEvents()
entity 1, added: MyTag1, added: MyTag2
*/

public readonly struct MySignal { }
public struct CollisionSignal {
public Entity other;
}

[Test]
public static void AddSignalHandler()
{
var store = new EntityStore();
var entity = store.CreateEntity();
entity.AddSignalHandler<MySignal>(signal => { Console.WriteLine(signal); }); // > entity: 1 - signal > MySignal
entity.EmitSignal(new MySignal());
var store = new EntityStore();
var player = store.CreateEntity(1);
player.AddSignalHandler<CollisionSignal>(signal => {
Console.WriteLine($"player collision with entity: {signal.Event.other.Id}");
// > player collision with entity: 2
});
var npc = store.CreateEntity(2);
// ... detect collision. e.g. with a collision system. In case of collision:
player.EmitSignal(new CollisionSignal{ other = npc });
}

}
Expand Down

0 comments on commit f856c94

Please sign in to comment.