Giter Site home page Giter Site logo

aether's Introduction

Aether

Unity Game Engine Event Management System

Feature Overview

  • global events with Event or events local to a context with ContextEvent
  • no need to remove listeners in OnDestroy for MonoBehaviours
  • event queue: all listeners of the original event are executed before any listener of a nested event
  • listener predicate conditions
  • 3 priority queues per event type
  • easy access to the last event of any type

Installation

Install via Add package from git URL in the Package Manager.

Basic Usage

Create a separate class for each event:

public class ExampleEvent : Aether.Event<ExampleEvent>
{
    public readonly int Variable;

    public ExampleEvent(int variable)
    {
        Variable = variable;
    }
}

Add listeners and remove when not needed anymore (they will be automatically removed when the game object gets destroyed):

public class ExampleListener : MonoBehaviour
{
    private void Awake()
    {
        ExampleEvent.AddListener(OnEvent);
    }

    private void OnEvent(ExampleEvent eventData)
    {
        Debug.Log(eventData.Variable);
        ExampleEvent.RemoveListener(OnEvent);
    }
}

Create a new event instance and invoke the event:

public class ExampleInvoker : MonoBehaviour, IPointerClickHandler
{
    public void OnPointerClick(PointerEventData eventData)
    {
        new ExampleEvent(0).Invoke();
    }
}

Good Practices

Use readonly fields or private setter properties as event parameters to prevent listeners from changing them. Use Awake to subscribe to events whenever possible and don't invoke any events until Start to be sure that all listeners have already subscribed.

Order of Execution

If you invoke a new event from an event listener, the original event will execute on all of the remaining listeners first.

Last Event of Type

Use Last property to access the last invoked event of a given type (can be null if the event hasn't been invoked yet).

Context Events

Inherit from ContextEvent instead and pass an additional context parameter when adding a listener and invoking the event. Only listeners with the same context as the event will be executed.

Priority

Pass an additional priority argument when adding a listener to invoke that listener pre or post other listeners for that event.

Predicate

Use predicate field when adding a listener to only invoke the listener if a condition is met.

Event Processed

Subscribe to EventProcessed event to handle all events of any type.

aether's People

Contributors

roxtone avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.