https://github.com/fluffyspectre/genericeventsystem
https://github.com/fluffyspectre/genericeventsystem
Last synced: 11 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/fluffyspectre/genericeventsystem
- Owner: FluffySpectre
- License: mit
- Created: 2023-08-28T19:42:26.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2023-08-28T19:42:40.000Z (almost 3 years ago)
- Last Synced: 2025-04-04T19:27:42.493Z (over 1 year ago)
- Language: C#
- Size: 6.84 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Generic Event System
This approach keeps the event data and the event management logic separate. It makes use of a templated static class which removes the need for a specialized event base class and explicit type casting.
## Usage:
### Emit Event
using GenericEventSystem;
// define a event class
public class EnemyKilledEvent {
public string EnemyName { get; set; }
public string KillerName { get; set; }
}
// setup event object
EnemyKilledEvent e = new EnemyKilledEvent();
e.EnemyName = "Goblin";
e.KillerName = "Slayer X";
// emit the event
EventSystem.Emit(e);
### Listen for Event
using GenericEventSystem;
EventSystem.EventHappened += (e) => {
Console.WriteLine(e.EnemyName + " killed by " + e.KillerName);
// do awesome stuff...
};