File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -11,11 +11,29 @@ public class MonoGlobalComponent : MonoBehaviour
11
11
{
12
12
private readonly List < Action > _toMainThreads = new ( ) ;
13
13
private volatile bool _isToMainThreadQueueEmpty = true ;
14
+ private List < Action > _localToMainThreads = new ( ) ;
14
15
internal event Action < bool > OnGamePause ;
15
16
internal event Action OnGameQuit ;
16
17
internal event Action < bool > OnGameFocus ;
17
18
18
19
20
+ private void Update ( )
21
+ {
22
+ if ( _isToMainThreadQueueEmpty ) return ;
23
+ _localToMainThreads . Clear ( ) ;
24
+ lock ( _toMainThreads )
25
+ {
26
+ _localToMainThreads . AddRange ( _toMainThreads ) ;
27
+ _toMainThreads . Clear ( ) ;
28
+ _isToMainThreadQueueEmpty = true ;
29
+ }
30
+
31
+ for ( int i = 0 ; i < _localToMainThreads . Count ; i ++ )
32
+ {
33
+ _localToMainThreads [ i ] . Invoke ( ) ;
34
+ }
35
+ }
36
+
19
37
private void OnApplicationFocus ( bool hasFocus )
20
38
{
21
39
OnGamePause ? . Invoke ( hasFocus ) ;
You can’t perform that action at this time.
0 commit comments