UnityMainThreadDispatcher
UnityMainThreadDispatcher copied to clipboard
A simple, thread-safe way of executing actions (Such as UI manipulations) on the Unity Main Thread
I love `UnityMainThreadDispatcher`; it solves a very simple problem well. However, I strongly dislike the static singleton anti-pattern used throughout the Unity ecosystem, and unfortunately this library is one of...
I tried to add the package to OpenUPM registry: https://openupm.com/packages/com.pimdewitte.unitymainthreaddispatcher/ It requires to have tags. Can we add some?
``` private void OnDisconnected() { LogUtils.log("OnDisconnected"); UnityMainThreadDispatcher.Instance().Enqueue(() => { InternetChecker.instance.InternetIsNotAvailable(); }); } ``` I have the above code, but in the logs "OnDisconnected" log is not seen. But the function...
Just be curious, what if an action is (computationally) heavy, does other thread wait for a long time for the lock to be released? ``` // UnityMainThreadDispatcher.cs public void Update()...
To enhance performances, avoid classic lock and use a SemaphoreSlim(1,1) light lock.
New functions added to pass actions with a generic parameter: - `Enqueue` - `EnqueueAsync` - `ActionWrapper` I am using these to pass received values from MQTT.
I added brackets and deleted comment
As mentioned in the readme, I use this class by creating an empty game object in a particular scene and attaching UnityMainThreadDispatcher.cs to it. it doesn't matter if you go...
* Added a static Dispatch Method that allows to get a return value from the Main Thread. * Added a static Dispatch Method that executes an Action to simplify usage.
Minor optimization - don't hold lock while executing queued actions.