Skip to content
This repository has been archived by the owner on Feb 10, 2024. It is now read-only.
/ GameFartsEventBus Public archive

A small Unity event management system using C# actions.

License

MIT, Unknown licenses found

Licenses found

MIT
LICENSE
Unknown
LICENSE.meta
Notifications You must be signed in to change notification settings

Abban/GameFartsEventBus

Repository files navigation

Game Farts Unity Event Bus

Vroom.

This is a small library to manage events in Unity.

Installation

You can install this in Unity as a Package by going to Window > Package Manager And then hitting the + and selecting Add Package from git URL.

Usage

To use it you can either instantiate a new EventBus in your container classes for injection or create one as a humble object in a singleton MonoBehaviour. If you want to use a singleton you can check out the installable example through the package manager.

Event Payloads

All events have a payload that has to implement the IEvent interface.

public class FireEvent : IEvent
{
    public Vector2 Direction { get; }

    public FireEvent(Vector2 direction)
    {
        Direction = direction;
    }
}

You can subscribe and unsubscribe to an event in your MonoBehaviours like this:

private void OnEnable()
{
    _eventBus.Subscribe<FireEvent>(OnFire);
}

private void OnDisable()
{
    _eventBus.Unsubscribe<FireEvent>(OnFire);
}

private void OnFire(FireEvent payload)
{
    Debug.Log( $"Firing in direction {payload.Direction}" );
}

And you can fire events like this:

var direction = new Vector2(
    Random.Range(-10f, 10f),
    Random.Range(-10f, 10f)
);

_eventBus.Fire(new FireEvent(direction));

About

A small Unity event management system using C# actions.

Resources

License

MIT, Unknown licenses found

Licenses found

MIT
LICENSE
Unknown
LICENSE.meta

Stars

Watchers

Forks

Packages

No packages published

Languages