From f856c9494799ce39e2215923a1ebf3f88900784d Mon Sep 17 00:00:00 2001 From: friflo Date: Wed, 8 Jan 2025 13:11:52 +0100 Subject: [PATCH] Examples: update AddSignalHandler() example --- src/Tests/ECS/Examples/General.cs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/Tests/ECS/Examples/General.cs b/src/Tests/ECS/Examples/General.cs index eec658eb..a9525d00 100644 --- a/src/Tests/ECS/Examples/General.cs +++ b/src/Tests/ECS/Examples/General.cs @@ -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(signal => { Console.WriteLine(signal); }); // > entity: 1 - signal > MySignal - entity.EmitSignal(new MySignal()); + var store = new EntityStore(); + var player = store.CreateEntity(1); + player.AddSignalHandler(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 }); } }