Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

[Open Source] Signals ❇ - A decoupled, typesafe messaging system

Discussion in 'Assets and Asset Store' started by Johannski, Jan 4, 2020.

  1. Johannski

    Johannski

    Joined:
    Jan 25, 2014
    Posts:
    823


    Signals
    https://github.com/supyrb/signals
    A typesafe, lightweight, tested messaging package for Unity.


    Features
    • Signal Hub as a global Registry for everyone to access
    • Signal with up to three parameters
    • Signal Listener Order
    • Consuming Signals
    • Pausing Signals
    • Editor Window to debug and control signals
    • Signal Logging for better understanding and instant feedback
    • UPM support
    • OpenUPM support
    • Experimental PlayMode support
    • Unit tests for runtime scripts
    • Sample packages to get started fast
    • XML comments for all public methods and properties
    Example:
    Code (CSharp):
    1. public class BasicExampleSignalTest : MonoBehaviour
    2. {
    3.     private BasicExampleSignal basicExampleSignal;
    4.     private void Awake()
    5.     {
    6.         Signals.Get(out basicExampleSignal);
    7.         SubscribeListeners();
    8.     }
    9.  
    10.     private void Start()
    11.     {
    12.         DispatchSignal();
    13.     }
    14.  
    15.     private void SubscribeListeners()
    16.     {
    17.         basicExampleSignal.AddListener(FirstListener, -100);
    18.         basicExampleSignal.AddListener(PauseTwoSecondsListener, -10);
    19.         basicExampleSignal.AddListener(DefaultListener);
    20.         basicExampleSignal.AddListener(ConsumeEventListener, 10);
    21.         basicExampleSignal.AddListener(LastListener, 100);
    22.     }
    23.  
    24.     private void OnDestroy()
    25.     {
    26.         basicExampleSignal.RemoveListener(FirstListener);
    27.         basicExampleSignal.RemoveListener(PauseTwoSecondsListener);
    28.         basicExampleSignal.RemoveListener(DefaultListener);
    29.         basicExampleSignal.RemoveListener(ConsumeEventListener);
    30.         basicExampleSignal.RemoveListener(LastListener);
    31.     }
    32.  
    33.     [ContextMenu("DispatchSignal")]
    34.     public void DispatchSignal()
    35.     {
    36.         basicExampleSignal.Dispatch();
    37.     }
    38.  
    39.     private void FirstListener()
    40.     {
    41.         Debug.Log("First Listener (Order -100)");
    42.     }
    43.  
    44.     private void PauseTwoSecondsListener()
    45.     {
    46.         Debug.Log("Pausing for 2 seconds (Order -10)");
    47.         basicExampleSignal.Pause();
    48.         StartCoroutine(ContinueAfterDelay(basicExampleSignal, 2f));
    49.     }
    50.  
    51.     private void DefaultListener()
    52.     {
    53.         Debug.Log("Default order Listener (Order 0)");
    54.     }
    55.  
    56.     private void ConsumeEventListener()
    57.     {
    58.         Debug.Log("Consume Signal (Order 10)");
    59.         basicExampleSignal.Consume();
    60.     }
    61.  
    62.     private void LastListener()
    63.     {
    64.         Debug.Log("Won't be called, since the signal was consumed. (Order 100)");
    65.     }
    66.  
    67.     private IEnumerator ContinueAfterDelay(Signal signal, float delay)
    68.     {
    69.         yield return new WaitForSeconds(delay);
    70.         signal.Continue();
    71.     }
    72. }
    The project is a fork of Yanko Oliveira's Signals, with additional functionality, quality assurance and package support.

    I hope that project helps others building clean and decoupled game logic. Any feedback is always welcome!

    Cheers
    Johannes
     
    Last edited: Apr 6, 2020
    StupydHors, SlimeProphet and valarnur like this.
  2. Johannski

    Johannski

    Joined:
    Jan 25, 2014
    Posts:
    823
    Got a nice update for you. With version 0.4 there is now an editor window that makes the whole UX a lot better:
    • See all signals, that are defined in a project.
    • Interact with signals (Dispatch, consume, Pause & Continue)
    • See all listeners subscribed to a signal with their order
    • Filter for signals to quickly get to the signal you want to look at
    The window brings together the type safety of classses with the ease of use of the unity editor we all love. This should help getting started a lot more easily.

    Happy messaging!
     
  3. Johannski

    Johannski

    Joined:
    Jan 25, 2014
    Posts:
    823
    Hello again,

    finally got around logging signals properly, now supported with version 0.5

    What does that mean? Well you can see and understand your signals a lot better now with the editor
    Signals-0.5.0.gif

    The listeners are color-coded for the last dispatched signal and you can instantly see when signals were dispatched.
    The experimental playmode is now also supported out of the box.
    The full changelog and downloads can be found over here: https://github.com/supyrb/signals/releases/tag/0.5.0

    Looking forward to feedback :)
     
    brunocoimbra likes this.
  4. SlimeProphet

    SlimeProphet

    Joined:
    Sep 30, 2019
    Posts:
    50
    This is incredible supyrb! Thank you.
     
    Johannski likes this.
  5. Johannski

    Johannski

    Joined:
    Jan 25, 2014
    Posts:
    823
    Very glad you found your way here and find use for the repo! This was one of the few things I missed for unity, so I thought others might miss it too. I'm always happy to get feedback/PRs/Issues, so if you find anything you do or don't like let me know :)