A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/KuraiAndras/MainThreadDispatcher.Unity below:

KuraiAndras/MainThreadDispatcher.Unity: Main thread dispatcher implementation for unity

This project moved to a mono repo.

MainThreadDispatcher.Unity

An implementation of the IMainThreadDispatcher interface in Unity 3D

Add a GameObject to you scene and add the UnityMainThreadDispatcher script to it. Make sure that this GameObject is in your scene.

//Getting an instance with static method
IMainThreadDispatcher dispatcher = UnityMainThreadDispatcherExtensions.Instance;

dispatcher.Invoke(() => Debug.Log("Hello 1"));
await dispatcher.InvokeAsync(() => Debug.Log("Hello 2"))

Button button = await dispatcher.InvokeAsync(() => GameObject.FindObjectOfType<Button>()))    

Calling the dispatcher is thread safe

If you call UnityMainThreadDispatcherExtensions.Instance before the the GameObject containing it is instantiated you will get an exception.

If you call UnityMainThreadDispatcherExtensions.Instance for the first time from a thread other than the main unity thread, you will get an exception.

If there are multiple instances in you scene, then when calling UnityMainThreadDispatcherExtensions.Instance it will cache the first it finds. Preferably you only want one instance of it in your application, having multiple does not provide any performance benefit


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4