// Sample usage
public static class Signaling
{
...
public static readonly Signal OnGameInit = new Signal();
public static readonly Signal<int> OnPlayerScore = new Signal<int>(); //newScore
...
}
public class GameManager : MonoBehaviour
{
private void Awake()
{
Signaling.OnGameInit.Invoke();
...
Signaling.OnPlayerScore.Invoke(10);
...
}
}
public class SomeView : MonoBehaviour
{
private void Start()
{
Signaling.OnGameInit.AddListener(Initialize);
Signaling.OnPlayerScore.AddListener(OnScore);
}
private void OnDestroy()
{
Signaling.OnGameInit.RemoveListener(Initialize);
Signaling.OnPlayerScore.RemoveListener(OnScore);
}
private void Initialize()
{
// display
}
private void OnScore(int newScore)
{
// update ui
}
}
-
Notifications
You must be signed in to change notification settings - Fork 0
cemuka/SignalSystem
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|