https://github.com/alexmalyutindev/unity-event-bus
https://github.com/alexmalyutindev/unity-event-bus
events unity upm upm-package
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/alexmalyutindev/unity-event-bus
- Owner: alexmalyutindev
- License: mit
- Created: 2021-09-12T13:23:13.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2021-09-12T14:37:28.000Z (almost 5 years ago)
- Last Synced: 2025-09-09T23:33:00.438Z (10 months ago)
- Topics: events, unity, upm, upm-package
- Language: C#
- Homepage:
- Size: 26.4 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
Unity Event Bus system.
==========
[](https://github.com/alexmalyutindev/unity-event-bus/actions/workflows/upm-ci.yml)
[](https://github.com/alexmalyutindev/unity-event-bus/releases)
Examples
--------
- Single subscription:
```c#
public class Foo : IDisposable
{
private IDisposable _sub;
public Foo(IEventBus eventBus)
{
_sub = eventBus.Subscribe(e => Debug.Log(e));
}
public void Dispose()
{
_sub.Dispose();
}
}
```
- Bus subscription using `IEventBusSubscriber` interface:
```c#
public class Foo : IEventBusSubscriber, IDisposable
{
private readonly IEventBus _eventBus;
public Foo(IEventBus eventBus)
{
_eventBus = eventBus;
_eventBus.Subscribe(this);
}
public void HandleEvent(T e)
{
switch (e)
{
case EventA a:
//...
break;
}
}
public void Dispose()
{
_eventBus.Unsubscribe(this);
}
}
```
- Fire events:
```c#
eventBus.Fire(new EventA());
```
Installation
------------
Find the manifest.json file in the Packages folder of your project and add a line to `dependencies` field:
* `"com.alexmalyutindev.event-bus": "https://github.com/alexmalyutindev/unity-event-bus.git#latest"`
Or, you can add this package using PackageManager `Add package from git URL` option:
* `https://github.com/alexmalyutindev/unity-event-bus.git#latest`