File tree 1 file changed +36
-0
lines changed
Proyecto26.RestClient/Helpers
1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change
1
+ using System ;
2
+ using System . Collections . Generic ;
3
+ using System . Collections . Concurrent ;
4
+ using UnityEngine ;
5
+
6
+ namespace Proyecto26 . Helper {
7
+
8
+ /// <summary>
9
+ /// Original solution from: https://stackoverflow.com/a/53818416/10305444
10
+ /// Should also read: https://gamedev.stackexchange.com/a/195298/126092
11
+ /// Usage:
12
+ /// ```
13
+ /// ExecuteOnMainThread.RunOnMainThread.Enqueue(() => {
14
+ /// Code here will be called in the main thread...
15
+ /// });
16
+ /// ```
17
+ /// </summary>
18
+ public class ExecuteOnMainThread : MonoBehaviour {
19
+
20
+ /// <summary>
21
+ /// Store all instance of Action's and try to invoke them
22
+ /// </summary>
23
+ public static readonly ConcurrentQueue < Action > RunOnMainThread = new ConcurrentQueue < Action > ( ) ;
24
+
25
+ /// <summary>
26
+ /// Unity's Update method
27
+ /// </summary>
28
+ void Update ( ) {
29
+ if ( ! RunOnMainThread . IsEmpty ) {
30
+ while ( RunOnMainThread . TryDequeue ( out var action ) ) {
31
+ action ? . Invoke ( ) ;
32
+ }
33
+ }
34
+ }
35
+ }
36
+ }
You can’t perform that action at this time.
0 commit comments