Event Bus
EventBus is a decoupled event system that dispatches published events to registered handlers based on event type. It eliminates direct component references, enabling clean architecture and runtime-configurable handler pipelines. Features include prioritized handlers, cancelable events, automatic type mapping, and IL2CPP support—ideal for building scalable systems and plugin architectures.
com.futuclass.event-bus 
Install via UPM
Add to Unity Package Manager using this URL
https://www.pkglnk.dev/event-bus.git README Markdown
Copy this to your project's README.md
## Installation
Add **Event Bus** to your Unity project via Package Manager:
1. Open **Window > Package Manager**
2. Click **+** > **Add package from git URL**
3. Enter:
```
https://www.pkglnk.dev/event-bus.git
```
[](https://www.pkglnk.dev/pkg/event-bus)README
EventBus 
EventBus is a system, which can dispatch published events to any registered handler accepting particular event argument. This means, that your event sources should no longer contain references to other components, only to event bus.
This creates a clean separation between event sources and handlers, and allows to build handler pipelines dynamically in runtime, rather than compile time. So in theory you can even load third-party libraries adopted for this Event Bus and insert their handlers into the pipeline. For example, this behavior can be used to implement plugin systems.
EventBus isn't thread-safe, be careful.
Features
- Custom event arguments.
- Automatic event data mapping to handlers by type.
- Ability to decouple code.
- Prioritized handlers.
- Cancelable events.
- Event pipeline building in runtime.
- IL2CPP support.
Installation
Install via OpenUPM
The package is available on the openupm registry. It's recommended to install it via openupm-cli.
openupm add com.futuclass.event-bus
Install via Git URL
Open Packages/manifest.json with your favorite text editor. Add the following line to the dependencies block.
{
"dependencies": {
"com.futuclass.event-bus": "https://github.com/Futuclass/EventBus.git"
}
}
Notice: Unity Package Manager records the current commit to a lock entry of the manifest.json. To update to the latest version, change the hash value manually or remove the lock entry to resolve the package.
"lock": {
"com.futuclass.event-bus": {
"revision": "master",
"hash": "..."
}
}
Usage
using Futuclass.EventBus;
using Futuclass.EventBus.Unity;
using System;
using UnityEngine;
public class ChatMessageArgs : CancelableEventBase
{
public string Message;
}
public class MessageSender : MonoBehaviour
{
public void SendChatMessage(string message)
{
GlobalEventBus.Publish(new ChatMessageArgs
{
Message = message
});
}
}
public class MessageProcessor : MonoBehaviourProxy
{
[Handler(HandlerPriority.High)]
public void HandleCommandMessage(ChatMessageArgs args)
{
if (!args.Message.StartsWith("/")) return;
// If it's a command, handle it and cancel the event
// Messages starting with / should be sent as regular chat messages
HandleCommand(args.Message);
args.Cancel();
}
[Handler(HandlerPriority.Medium)]
public void HandleRegularMessage(ChatMessageArgs args)
{
if(args.Canceled) return;
SendMessageToChat(args.Message);
}
}
Credits
Based on Salday/EventBus
Comments
No comments yet. Be the first!
Sign in to join the conversation
Sign In