Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/yankooliveira/signals
A typesafe, lightweight messaging lib for Unity.
https://github.com/yankooliveira/signals
Last synced: 3 months ago
JSON representation
A typesafe, lightweight messaging lib for Unity.
- Host: GitHub
- URL: https://github.com/yankooliveira/signals
- Owner: yankooliveira
- License: mit
- Created: 2018-01-16T02:29:21.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2021-06-05T18:52:15.000Z (over 3 years ago)
- Last Synced: 2024-07-14T04:38:24.155Z (4 months ago)
- Language: C#
- Size: 9.77 KB
- Stars: 212
- Watchers: 13
- Forks: 34
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-unity-open-source-on-github - signals - A typesafe, lightweight messaging lib (Message Bus)
README
# Signals
### A typesafe, lightweight messaging lib for Unity.
---
Inspired by StrangeIOC, minus the clutter.
Originally based on [CSharpMessenger](http://wiki.unity3d.com/index.php/CSharpMessenger_Extended).
Converted to use strongly typed parameters and prevent use of strings as ids.Special thanks to Max Knoblich for code review and Aswhin Sudhir for the anonymous function asserts suggestion.
Supports up to 3 parameters (more than that, and you should probably use a specialized VO as a single parameter).
You can read about the reasons behind it [on my blog](http://yankooliveira.com/index.php/2018/01/15/signals).### Usage:
1) Define your signal with up to 3 payload parameters, eg:
```c#
public class EndGameSignal : ASignal {}
public class ScoreSignal : ASignal {}
```
2) Add listeners on portions that should react, eg on Awake():
```c#
Signals.Get().AddListener(OnScore);
```
3) Dispatch, eg:
```c#
Signals.Get().Dispatch(playerName, playerScore);
```
4) Don't forget to remove the listeners upon destruction! Eg on OnDestroy():
```c#
Signals.Get().RemoveListener(OnScore);
```
5) You also have your local Signal Hub that is specific to a given object instead of using the global one. The syntax is exactly the same.
```c#
SignalHub playerSignals = new SignalHub();
playerSignals.Get().Dispatch(playerName, playerScore);
```Hit me up on [twitter](https://twitter.com/yankooliveira) for any suggestions or questions.