Skip to content

Commit bb7d1ba

Browse files
committed
Update MonoGlobalComponent.cs
1 parent 1f0ca40 commit bb7d1ba

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

VirtueSky/Global/MonoGlobalComponent.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,29 @@ public class MonoGlobalComponent : MonoBehaviour
1111
{
1212
private readonly List<Action> _toMainThreads = new();
1313
private volatile bool _isToMainThreadQueueEmpty = true;
14+
private List<Action> _localToMainThreads = new();
1415
internal event Action<bool> OnGamePause;
1516
internal event Action OnGameQuit;
1617
internal event Action<bool> OnGameFocus;
1718

1819

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+
1937
private void OnApplicationFocus(bool hasFocus)
2038
{
2139
OnGamePause?.Invoke(hasFocus);

0 commit comments

Comments
 (0)