Skip to content
This repository has been archived by the owner on Oct 13, 2020. It is now read-only.

erlioniel/unity-smessage

Repository files navigation

!!! Deprecation disclaimer

This code isn't supported anymore. Please use it only if you are really interested in this approach. As a better alternative I recommend (and actually using in my projects) Signals by dimmpixeye

SMessage for Unity

The small and simple, but powerful and strict-typed messaging system for Unity engine. I've created it for using in my own projects, but shared it after post on Habrahabr (RUS https://habrahabr.ru/post/245353/)

Getting Started

Just include all script files somewhere in your own project, for example Assets/Vendor/SMessage and start using it!

Create event class with GameObject value

public class SMessageExample :  AbstractSMessageValued<GameObject> {
  public SMessageExample (GameObject value) : base(value) { }
}

Create call of this event in someone MonoBehaviour class

public class ExampleObject : MonoBehaviour {
  public void OnMouseDown () {
    SManager.SCall(new SMessageExample(gameObject));
  }
}

Add handler for this event in another MonoBehaviour class

public class ExampleHandlerObject : MonoBehaviour {
    // Add event listener in OnEnable callback
    public void OnEnable() {
      SManager.SAdd<SMessageExample>(OnMessage);
    }

    // And remove in OnDisable callback
    public void OnDisable() {
      SManager.SRemove<SMessageExample>(OnMessage);
    }

    private void OnMessage (SMessageExample message) {
      Debug.Log("OnMouseDown for object "+message.Value.name);
    }
}

More examples

Prerequisites

  • Unity3D
  • Hands

Running the tests

Tests are not yet writen, but they will be somewhen.

Contributing

Feel free to create issues and contribute your code!

Authors

License

This project is licensed under the WTFPL - see the license.txt file for details

About

Unity simple message system

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages