Skip to content
プロジェクト

概要

A typesafe, lightweight messaging lib for Unity.

仕事効率化・自動化

この数値の測り方

計測したスター増加

24時間
0
7日間
0
15日間
0
1か月
履歴を収集中

期間ごとの純増数です。期間は重複しており、日別の値ではありません。未計測の値は空欄です。スター数は注目度の指標であり、品質の保証ではありません。

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:

  1. Define your signal with up to 3 payload parameters, eg:
public class EndGameSignal : ASignal {}
public class ScoreSignal : ASignal<string, int> {}
  1. Add listeners on portions that should react, eg on Awake():
Signals.Get<ScoreSignal>().AddListener(OnScore);
  1. Dispatch, eg:
Signals.Get<ScoreSignal>().Dispatch(playerName, playerScore);
  1. Don't forget to remove the listeners upon destruction! Eg on OnDestroy():
Signals.Get<ScoreSignal>().RemoveListener(OnScore);
  1. 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.

関連プロジェクトを探す

読み込み中…