This is a wrapper class for executing heavy calculations without freezing the main thread but still using Unity's api (like transform.position, Instantiate, Destroy, etc).
-
Exec(System.Action action) //Method Synchronous
Executes an action on the main thread, and freezes its caller thread until execution.
-
ExecAsync(System.Action action) //Method Asynchronous
Executes an action on the main thread without freezing.
-
IsRunning //Boolean Field
Tells if you had already initialized the MainThread class.
-
OnExceptionCaught(Exception ex) //Error Event
If any exception occurs while executing the actions, this event will be fired.
-
Time since last call for each thread.
DeltaTime //Float Field
Try to minimize MainThread.Exec usage, as every call will add at least 25ms to your code. If you are using the MainThread.ExecAsync in a loop be sure to add a Thread.Sleep to not overflow the execution pool.