diff --git a/UniTAS/Patcher/MonoBehaviourScripts/MonoBehaviourUpdateInvoker.cs b/UniTAS/Patcher/MonoBehaviourScripts/MonoBehaviourUpdateInvoker.cs index ae37b81d..fbc18799 100644 --- a/UniTAS/Patcher/MonoBehaviourScripts/MonoBehaviourUpdateInvoker.cs +++ b/UniTAS/Patcher/MonoBehaviourScripts/MonoBehaviourUpdateInvoker.cs @@ -22,7 +22,8 @@ private void Awake() _monoBehEventInvoker.InvokeAwake(); - StartCoroutine(WhileCoroutine()); + StartCoroutine(EndOfFrameCoroutine()); + StartCoroutine(FixedUpdateCoroutine()); } private void OnDestroy() @@ -60,25 +61,33 @@ private void OnEnable() _monoBehEventInvoker.InvokeOnEnable(); } + private void OnApplicationFocus(bool hasFocus) + { + _logger.LogDebug($"game in focus = {hasFocus}"); + _gameInfo.IsFocused = hasFocus; + } + // stupid optimization since object alloc private readonly WaitForEndOfFrame _waitForEndOfFrame = new(); private readonly WaitForFixedUpdate _waitForFixedUpdate = new(); - private IEnumerator WhileCoroutine() + private IEnumerator EndOfFrameCoroutine() { while (true) { - yield return _waitForFixedUpdate; - _monoBehEventInvoker.CoroutineFixedUpdate(); yield return _waitForEndOfFrame; _monoBehEventInvoker.InvokeLastUpdate(); } // ReSharper disable once IteratorNeverReturns } - private void OnApplicationFocus(bool hasFocus) + private IEnumerator FixedUpdateCoroutine() { - _logger.LogDebug($"game in focus = {hasFocus}"); - _gameInfo.IsFocused = hasFocus; + while (true) + { + yield return _waitForFixedUpdate; + _monoBehEventInvoker.CoroutineFixedUpdate(); + } + // ReSharper disable once IteratorNeverReturns } } \ No newline at end of file