Skip to content
This repository has been archived by the owner on Nov 13, 2024. It is now read-only.

API Reference

Eric Sexton edited this page May 5, 2022 · 2 revisions

Namespace: CallbackEvents

The namespace for the Unity Callback Events System.

delegate: Task CallbackEvents.AsyncEvent(T e);

The type for async event callbacks.

delegate: T CallbackEvents.Filter(T e);

The type for filter callbacks.

MonoBehavior: CallbackEvents.EventSystem

This MonoBehavior is responsible for handling all of the events in a scene. It follows the singlet pattern, and thus should only be put into a scene once. If not placed in a scene where events are fired, there will be an error.

EventSystem.Current

  • <EventSystem> Static property that gets the instance of the event system. It May not exist in the awake function context or if an EventSystem MonoBehavior does not exist in the scene.

eventSystem.RegisterEventListener<T>(Action<T> listener)

  • Arguments
    • listener <Action<T>> The callback function for the event
  • Generics
    • T extends <EventContext> What type will used as the first parameter of the listener.
  • Returns: <void>

Registers an event listener for Type T.

eventSystem.UnregisterEventListener<T>(Action<T> listener)

  • Arguments
    • listener <Action<T>> The callback function for the event
  • Generics
    • T extends <EventContext> What type will used as the first parameter of the listener.
  • Returns: <bool> If the event listener was successfully deregistered

Deregister a previously registered event listener.

eventSystem.RegisterAsyncEventListener<T>(AsyncEvent<T> listener)

  • Arguments
    • listener <AsyncEvent<T>> The callback function for the event
  • Generics
    • T extends <EventContext> What type will used as the first parameter of the listener.
  • Returns: <void>

For registering event listeners that can run asynchronously with other events.

eventSystem.UnregisterAsyncEventListener<T>(AsyncEvent<T> listener)

  • Arguments
    • listener <AsyncEvent<T>> The callback function for the event
  • Generics
    • T extends <EventContext> What type will used as the first parameter of the listener.
  • Returns: <bool> If the event listener was successfully deregistered

Deregister a previously registered async event listener.

eventSystem.FireEvent(EventContext eventContext, int maxCallbackPerFrame = 0)

  • Arguments
    • eventContext <EventContext> The event data and type.
    • maxCallbackPerFrame <int> OPTIONAL. The number of event callbacks that can be run per frame. If any number higher than 0 is passed, the list of callback functions will be divided up by this number and run over multiple frames for performance.
  • Returns: <void>

For firing a specific event type.

eventSystem.FireEventAfter(EventContext eventContext, int ms, bool debounce = false, int maxCallbackPerFrame = 0)

  • Arguments
    • eventContext <EventContext> The event data and type.
    • ms <int> The number of milliseconds to wait before firing an event
    • debounce <bool> OPTIONAL. If true, if an event is queued to fire while another event of the same type is still queued to fire, it will not queue the 2nd event.
    • maxCallbackPerFrame <int> OPTIONAL. The number of event callbacks that can be run per frame. If any number higher than 0 is passed, the list of callback functions will be divided up by this number and run over multiple frames for performance.
  • Returns: <Action> a function to cancel the queued event before it is fired.

For firing a specific event type after a delay.

eventSystem.CallbackAfter(Action callback, int ms, bool debounce = false)

  • Arguments
    • eventContext <Action> The callback function.
    • ms <int> The number of milliseconds to wait before firing an event
    • debounce <bool> OPTIONAL. If true, if an event is queued to fire while another event of the same type is still queued to fire, it will not queue the 2nd event.
  • Returns: <Action> a function to cancel the queued callback before it is fired.

A convenience function for running a specific callback after a delay.

eventSystem.AsyncFireEvent(EventContext eventContext)

  • Arguments
    • eventContext <EventContext> The event data and type.
  • Returns: a task that is awaiting all listeners to finish.

Fires all the async listeners for an event type.

eventSystem.RegisterFilterListener<T>(Filter<T> listener, int priority = 0)

  • Arguments
    • listener <Filter<T>> The callback function for the filter
    • priority <int> OPTIONAL. If passed sets the priority of the filter. The higher priority, the earlier it runs in the filter chain.
  • Generics
    • T extends <EventContext> What type will be used as the first parameter of the listener.
  • Returns: <void>

Register a filter listener to a specific filter type.

eventSystem.UnregisterFilterListener<T>(Filter<T> listener)

  • Arguments
    • listener <Filter<T>> The callback function for the filter
  • Returns: <bool> If the listener was successfully removed.

Deregister is a filter listener to a specific filter type.

eventSystem.FireFilter<T>(EventContext eventContext)

  • Arguments
    • eventContext <EventContext> The filter data and type.
  • Generics
    • T extends <EventContext> What type will be used as the first parameter of the listener.
  • Returns <T> The modified filter data.