https://github.com/ahmkam/unity-simple-message-broker
A simple message broker for C# and Unity
https://github.com/ahmkam/unity-simple-message-broker
csharp message-broker pub-sub publisher-subscriber publisher-subscriber-pattern unity unity-plugin
Last synced: 4 months ago
JSON representation
A simple message broker for C# and Unity
- Host: GitHub
- URL: https://github.com/ahmkam/unity-simple-message-broker
- Owner: ahmkam
- License: mit
- Created: 2020-11-05T17:07:19.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2020-11-18T22:32:09.000Z (over 5 years ago)
- Last Synced: 2025-03-11T09:53:37.485Z (over 1 year ago)
- Topics: csharp, message-broker, pub-sub, publisher-subscriber, publisher-subscriber-pattern, unity, unity-plugin
- Language: C#
- Homepage:
- Size: 30.3 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Simple Message Broker
A simple message broker for C# and Unity inspired by UniRx message broker
### Usage
Copy the Plugins/SimpleMessageBroker folder into your project or download the latest [unity package](https://github.com/ahmkam/unity-simple-message-broker/releases/download/2.0/UnitySimpleMessageBroker-v2.0.unitypackage) from releases
Sending / receiving empty message
```csharp
// Your function
public void Foo() => Debug.Log("Foo");
// Subscribe message
SimpleMessageBroker.Subscribe("foo_id", Foo);
// Publish message
SimpleMessageBroker.Publish("foo_id");
// Unsubscribe message
SimpleMessageBroker.Unsubscribe("foo_id", Foo);
```
Sending / receiving with a message class. An ID can be given if you want to filter messages of the same class
```csharp
// Message class
public class FooArgs
{
public string value;
}
// Your function
public void FooWithMessage(FooArgs arg) => Debug.Log(arg.value);
// Subscribe message
SimpleMessageBroker.Subscribe("foo_id", FooWithMessage);
// Publish
SimpleMessageBroker.Publish("foo_id", new FooArgs() { value = "hello world" });
// Unsubscribe
SimpleMessageBroker.Unsubscribe("foo_id", FooWithMessage);
```
-------------
### Todo
- ~~Filtering messages belonging to the same message class~~
- Utility methods
- Error checking