Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/paulnonatomic/messageservice
A simple Unity C# messaging system
https://github.com/paulnonatomic/messageservice
Last synced: 1 day ago
JSON representation
A simple Unity C# messaging system
- Host: GitHub
- URL: https://github.com/paulnonatomic/messageservice
- Owner: PaulNonatomic
- License: mit
- Created: 2024-02-11T23:21:09.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2024-04-01T22:27:58.000Z (9 months ago)
- Last Synced: 2024-11-09T08:36:49.889Z (about 2 months ago)
- Language: C#
- Homepage:
- Size: 22.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# MessageService
## Overview
MessageService is a simple message passing system for decoupling components in a Unity application. It provides a mechanism for subscribing to messages of a specific type and publishing messages to all interested subscribers.## Installation
To install MessageService in your Unity project, add the package from the git URL: `https://github.com/PaulNonatomic/MessageService.git` using the Unity package manager.## Features
- **Subscribe to Messages**: Listen for specific message types.
- **Unsubscribe from Messages**: Stop listening for specific message types.
- **Publish Messages**: Send messages to all subscribers of that message type.
- **Automatically unsubscribe**: After receiving a message once with SubscribeOnce feature## Usage
### Subscribing to a Message
To subscribe to a message type, use the `Subscribe` method where `T` is your message type:```csharp
_messageService.Subscribe(HandleMyMessage);private void HandleMyMessage(MyMessage message)
{
// Handle the message
}
```### Unsubscribing from a Message
To unsubscribe, use the Unsubscribe method:```csharp
_messageService.Unsubscribe(HandleMyMessage);
```### Publishing a Message
To publish a message, use the Publish method:```csharp
_messageService.Publish(new MyMessage { Content = "Hello, world!" });
```
### Subscribe Once
Messages can be subscribed to be received only once using SubscribeOnce. After the message is received for the first time, the handler is automatically unsubscribed.```csharp
_messageService.SubscribeOnce(HandleMyMessage);
```
## Contributing
Contributions to MessageService are welcome! Please refer to CONTRIBUTING.md for guidelines on contributing to the project.## License
MessageService is licensed under the MIT license. See LICENSE for more details.