项目
在 GitHub 查看
yankooliveira/signals
关于
A typesafe, lightweight messaging lib for Unity.
效率与自动化实测星标增长
- 24小时
- 0
- 7天
- 0
- 15天
- 0
- 1个月
- 正在收集历史
各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。
README.md
原文Signals
A typesafe, lightweight messaging lib for Unity.
Inspired by StrangeIOC, minus the clutter. Originally based on CSharpMessenger. 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.
Usage:
- Define your signal with up to 3 payload parameters, eg:
public class EndGameSignal : ASignal {}
public class ScoreSignal : ASignal<string, int> {}
- Add listeners on portions that should react, eg on Awake():
Signals.Get<ScoreSignal>().AddListener(OnScore);
- Dispatch, eg:
Signals.Get<ScoreSignal>().Dispatch(playerName, playerScore);
- Don't forget to remove the listeners upon destruction! Eg on OnDestroy():
Signals.Get<ScoreSignal>().RemoveListener(OnScore);
- 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.
SignalHub playerSignals = new SignalHub();
playerSignals.Get<ScoreSignal>().Dispatch(playerName, playerScore);
Hit me up on twitter for any suggestions or questions.
探索相关项目
加载中…