mirror of
https://github.com/MartinKral/Slash-The-Hordes
synced 2025-12-08 21:59:26 +00:00
Added object pool, event system collision system
This commit is contained in:
16
assets/Scripts/Services/EventSystem/Signal.ts
Normal file
16
assets/Scripts/Services/EventSystem/Signal.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { ISignal } from "./ISignal";
|
||||
|
||||
export class Signal<T> implements ISignal<T> {
|
||||
private handlers: ((data: T) => void)[] = [];
|
||||
|
||||
public on(handler: (data: T) => void): void {
|
||||
this.handlers.push(handler);
|
||||
}
|
||||
public off(handler: (data: T) => void): void {
|
||||
this.handlers = this.handlers.filter((h) => h !== handler);
|
||||
}
|
||||
|
||||
public trigger(data: T): void {
|
||||
[...this.handlers].forEach((handler) => handler(data));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user