Skip to content

Files

Latest commit

 

History

History
69 lines (57 loc) · 2.83 KB

README.md

File metadata and controls

69 lines (57 loc) · 2.83 KB

Unity Events Framework

Unity Event Framework
Unity Event Framework is a simple and elegant way to handle events between your objects in Unity. The framework uses the PubSub pattern with current Payload states for easy access to previously sent events.

Inspired by the work of SuperMaxim

Why is that necessary?

There are several advantages to this approach, ranging from reducing cohesion in your project by not directly referencing objects to resolving asynchronous events within the project. You can also retrieve the state of an event at any time if it has been previously sent.

Get Started

Installation process:

Unity Package Manager URL:

https://github.com/DevsDaddy/UnityEventFramework.git?path=/DevsDaddy/Shared/EventFramework/

Usage

Create Payload (Event Model) for your Events:

public class TestPayload : IPayload
{
    public string Message = "";
}

To Subscribe for Payload (event) you can add listener via EventMessenger Class:

EventMessenger.Main.Subscribe<TestPayload>(payload => {
    Debug.Log(payload.Message);
});

To Publish New Payload (Event) you can:*

EventMessenger.Main.Publish(new TestPayload {
    Message = "Hello world!"
});

Also you can get latest state for any early published payload (or null if not published yet):*

TestPayload currentPayload = EventMessenger.Main.GetState<TestPayload>();
Debug.Log(currentPayload.Message);

Examples

See framework usage examples in other projects:

Coming Soon (TO-DO)

I plan to add the following functionality in the near future:

  • Reactive Fields with Auto-Resolving via EventMessenger Class;

Join Community

Support Me

You can support the development and updating of libraries and assemblies by dropping a coin:

Bitcoin (BTC)bc1qef2d34r4xkrm48zknjdjt7c0ea92ay9m2a7q55
Etherium (ETH)0x1112a2Ef850711DF4dE9c432376F255f416ef5d0
Boostyhttps://boosty.to/devsdaddy