Skip to main content
Version: 2.1.1

Haply::Inverse::Unity::EventDispatcher

A thread-safe class which holds a queue with actions to execute on the next Update method. More...

Inherits from Haply.Inverse.Unity.Utilities.Singleton< EventDispatcher >, MonoBehaviour

Public Functions

Name
voidEnqueue(IEnumerator action)
Locks the queue and adds the IEnumerator to the queue.
voidEnqueue(Action action)
Locks the queue and adds the Action to the queue.
voidEnqueue(UnityEvent action)
Locks the queue and adds the Action to the queue.
voidEnqueue< T >(Action< T > action, T arg)
Locks the queue and adds the Action (with a parameter T) to the queue.
voidEnqueue< T >(UnityEvent< T > action, T arg)
Locks the queue and adds the Action (with a parameter T) to the queue.
voidEnqueue< T0, T1 >(Action< T0, T1 > action, T0 arg0, T1 arg1)
Locks the queue and adds the Action (with two parameters T0 and T1) to the queue.
voidEnqueue< T0, T1 >(UnityEvent< T0, T1 > action, T0 arg0, T1 arg1)
Locks the queue and adds the UnityEvent (with two parameters T0 and T1) to the queue.
voidEnqueue< T0, T1, T2 >(Action< T0, T1, T2 > action, T0 arg0, T1 arg1, T2 arg2)
Locks the queue and adds the Action (with tree parameters T0, T1 and T2) to the queue.
voidEnqueue< T0, T1, T2 >(UnityEvent< T0, T1, T2 > action, T0 arg0, T1 arg1, T2 arg2)
Locks the queue and adds the UnityEvent (with tree parameters T0, T1 and T2) to the queue.
TaskEnqueueAsync(Action action)
Locks the queue and adds the Action to the queue, returning a Task which is completed when the action completes.
TaskEnqueueAsync(UnityEvent action)
Locks the queue and adds the Action to the queue, returning a Task which is completed when the action completes.
TaskEnqueueAsync< T >(Action< T > action, T arg)
Locks the queue and adds the Action to the queue, returning a Task which is completed when the action completes.
TaskEnqueueAsync< T >(UnityEvent< T > action, T arg)
Locks the queue and adds the Action to the queue, returning a Task which is completed when the action completes.

Protected Functions

Name
virtual override voidAwake()
virtual override voidUpdate()

Public Properties

Name
boolIsMainThread

Additional inherited members

Public Functions inherited from Haply.Inverse.Unity.Utilities.Singleton< EventDispatcher >

Name
boolExists()

Protected Functions inherited from Haply.Inverse.Unity.Utilities.Singleton< EventDispatcher >

Name
virtual voidOnEnable()
virtual voidOnDisable()
virtual voidOnDestroy()
virtual voidOnApplicationQuit()

Public Properties inherited from Haply.Inverse.Unity.Utilities.Singleton< EventDispatcher >

Name
TInstance
Gets the instance of the singleton class.

Detailed Description

class Haply::Inverse::Unity::EventDispatcher;

A thread-safe class which holds a queue with actions to execute on the next Update method.

It can be used to make calls to the main thread for things such as UI Manipulation in Unity. It was developed for use in combination with the Firebase Unity plugin, which uses separate threads for event handling

Author: Pim de Witte (pimdewitte.com) and contributors, https://github.com/PimDeWitte/UnityMainThreadDispatcher

Public Functions Documentation

function Enqueue

void Enqueue(
IEnumerator action
)

Locks the queue and adds the IEnumerator to the queue.

Parameters:

  • action IEnumerator function that will be executed from the main thread.

function Enqueue

void Enqueue(
Action action
)

Locks the queue and adds the Action to the queue.

Parameters:

  • action function that will be executed from the main thread.

function Enqueue

void Enqueue(
UnityEvent action
)

Locks the queue and adds the Action to the queue.

Parameters:

  • action function that will be executed from the main thread.

function Enqueue< T >

void Enqueue< T >(
Action< T > action,
T arg
)

Locks the queue and adds the Action (with a parameter T) to the queue.

Parameters:

  • action function (requires parameter of type T) that will be executed from the main thread.
  • arg parameter of type T to pass to action.

Template Parameters:

  • T The type of the parameter for the action.

function Enqueue< T >

void Enqueue< T >(
UnityEvent< T > action,
T arg
)

Locks the queue and adds the Action (with a parameter T) to the queue.

Parameters:

  • action function (requires parameter of type T) that will be executed from the main thread.
  • arg parameter of type T to pass to action.

Template Parameters:

  • T The type of the parameter for the action.

function Enqueue< T0, T1 >

void Enqueue< T0, T1 >(
Action< T0, T1 > action,
T0 arg0,
T1 arg1
)

Locks the queue and adds the Action (with two parameters T0 and T1) to the queue.

Parameters:

  • action function (requires parameters of type T0 and T1) that will be executed from the main thread.
  • arg0 parameter of type T0 to pass to action.
  • arg1 parameter of type T1 to pass to action.

Template Parameters:

  • T0 The type of the first parameter for the action.
  • T1 The type of the second parameter for the action.

function Enqueue< T0, T1 >

void Enqueue< T0, T1 >(
UnityEvent< T0, T1 > action,
T0 arg0,
T1 arg1
)

Locks the queue and adds the UnityEvent (with two parameters T0 and T1) to the queue.

Parameters:

  • action function (requires parameters of type T0 and T1) that will be executed from the main thread.
  • arg0 parameter of type T0 to pass to action.
  • arg1 parameter of type T1 to pass to action.

Template Parameters:

  • T0 The type of the first parameter for the action.
  • T1 The type of the second parameter for the action.

function Enqueue< T0, T1, T2 >

void Enqueue< T0, T1, T2 >(
Action< T0, T1, T2 > action,
T0 arg0,
T1 arg1,
T2 arg2
)

Locks the queue and adds the Action (with tree parameters T0, T1 and T2) to the queue.

Parameters:

  • action function (requires parameters of type T0, T1 and T2) that will be executed from the main thread.
  • arg0 parameter of type T0 to pass to action.
  • arg1 parameter of type T1 to pass to action.
  • arg2 parameter of type T2 to pass to action.

Template Parameters:

  • T0 The type of the first parameter for the action.
  • T1 The type of the second parameter for the action.
  • T2 The type of the third parameter for the action.

function Enqueue< T0, T1, T2 >

void Enqueue< T0, T1, T2 >(
UnityEvent< T0, T1, T2 > action,
T0 arg0,
T1 arg1,
T2 arg2
)

Locks the queue and adds the UnityEvent (with tree parameters T0, T1 and T2) to the queue.

Parameters:

  • action function (requires parameters of type T0, T1 and T2) that will be executed from the main thread.
  • arg0 parameter of type T0 to pass to action.
  • arg1 parameter of type T1 to pass to action.
  • arg2 parameter of type T2 to pass to action.

Template Parameters:

  • T0 The type of the first parameter for the action.
  • T1 The type of the second parameter for the action.
  • T2 The type of the third parameter for the action.

function EnqueueAsync

Task EnqueueAsync(
Action action
)

Locks the queue and adds the Action to the queue, returning a Task which is completed when the action completes.

Parameters:

  • action function that will be executed from the main thread.

Return: A Task that can be awaited until the action completes

function EnqueueAsync

Task EnqueueAsync(
UnityEvent action
)

Locks the queue and adds the Action to the queue, returning a Task which is completed when the action completes.

Parameters:

  • action function that will be executed from the main thread.

Return: A Task that can be awaited until the action completes

function EnqueueAsync< T >

Task EnqueueAsync< T >(
Action< T > action,
T arg
)

Locks the queue and adds the Action to the queue, returning a Task which is completed when the action completes.

Parameters:

  • action function that will be executed from the main thread.
  • arg parameter of type T to pass to action.

Template Parameters:

  • T The type of the parameter for the action.

Return: A Task that can be awaited until the action completes

function EnqueueAsync< T >

Task EnqueueAsync< T >(
UnityEvent< T > action,
T arg
)

Locks the queue and adds the Action to the queue, returning a Task which is completed when the action completes.

Parameters:

  • action function that will be executed from the main thread.
  • arg parameter of type T to pass to action.

Template Parameters:

  • T The type of the parameter for the action.

Return: A Task that can be awaited until the action completes

Protected Functions Documentation

function Awake

virtual override void Awake()

Reimplements: Haply::Inverse::Unity::Utilities::Singleton::Awake

function Update

virtual override void Update()

Reimplements: Haply::Inverse::Unity::Utilities::Singleton::Update

Public Property Documentation

property IsMainThread

static bool IsMainThread;