Twilight Princess
Remastered version of the GameCube game
Loading...
Searching...
No Matches
UnityMainThreadDispatcher Class Reference

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. More...

+ Inheritance diagram for UnityMainThreadDispatcher:
+ Collaboration diagram for UnityMainThreadDispatcher:

Public Member Functions

void Update ()
 
void Enqueue (IEnumerator action)
 Locks the queue and adds the IEnumerator to the queue.
 
void Enqueue (Action action)
 Locks the queue and adds the Action to the queue.
 
Task EnqueueAsync (Action action)
 Locks the queue and adds the Action to the queue, returning a Task which is completed when the action completes.
 

Static Public Member Functions

static bool Exists ()
 
static UnityMainThreadDispatcher Instance ()
 

Private Member Functions

IEnumerator ActionWrapper (Action a)
 
void Awake ()
 
void OnDestroy ()
 

Static Private Attributes

static readonly Queue< Action > _executionQueue = new Queue<Action>()
 
static UnityMainThreadDispatcher _instance = null
 

Detailed Description

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

Member Function Documentation

◆ ActionWrapper()

IEnumerator UnityMainThreadDispatcher.ActionWrapper ( Action a)
private

◆ Awake()

void UnityMainThreadDispatcher.Awake ( )
private

◆ Enqueue() [1/2]

void UnityMainThreadDispatcher.Enqueue ( Action action)

Locks the queue and adds the Action to the queue.

Parameters
actionfunction that will be executed from the main thread.

◆ Enqueue() [2/2]

void UnityMainThreadDispatcher.Enqueue ( IEnumerator action)

Locks the queue and adds the IEnumerator to the queue.

Parameters
actionIEnumerator function that will be executed from the main thread.

◆ EnqueueAsync()

Task UnityMainThreadDispatcher.EnqueueAsync ( Action action)

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

Parameters
actionfunction that will be executed from the main thread.
Returns
A Task that can be awaited until the action completes

◆ Exists()

static bool UnityMainThreadDispatcher.Exists ( )
static

◆ Instance()

static UnityMainThreadDispatcher UnityMainThreadDispatcher.Instance ( )
static

◆ OnDestroy()

void UnityMainThreadDispatcher.OnDestroy ( )
private

◆ Update()

void UnityMainThreadDispatcher.Update ( )

Member Data Documentation

◆ _executionQueue

readonly Queue<Action> UnityMainThreadDispatcher._executionQueue = new Queue<Action>()
staticprivate

◆ _instance

UnityMainThreadDispatcher UnityMainThreadDispatcher._instance = null
staticprivate

The documentation for this class was generated from the following file: