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
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/)
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
- Unity3D
- Hands
Tests are not yet writen, but they will be somewhen.
Feel free to create issues and contribute your code!
- Vladimir Kryukov - Erlioniel
This project is licensed under the WTFPL - see the license.txt file for details