@@ -492,14 +492,16 @@ private sealed class AsyncUtilityBehaviour : MonoBehaviour
492492 {
493493 #region data
494494
495+ private WaitForEndOfFrame _eof ;
496+ private Coroutine _eofCoroutine ;
497+
495498 private Dictionary < object , Action > _ops ;
496499 private List < KeyValuePair < object , Action > > _opsToRemove ;
497500
498501 private AsyncUpdateSource _updateSource ;
499502 private AsyncUpdateSource _lateUpdateSource ;
500503 private AsyncUpdateSource _fixedUpdateSource ;
501504 private AsyncUpdateSource _eofUpdateSource ;
502- private WaitForEndOfFrame _eof ;
503505
504506#if NET_4_6 || NET_STANDARD_2_0
505507
@@ -567,8 +569,11 @@ public IAsyncUpdateSource EofUpdateSource
567569 if ( _eofUpdateSource == null )
568570 {
569571 _eofUpdateSource = new AsyncUpdateSource ( ) ;
570- _eof = new WaitForEndOfFrame ( ) ;
571- StartCoroutine ( EofEnumerator ( ) ) ;
572+ }
573+
574+ if ( _eofCoroutine == null )
575+ {
576+ _eofCoroutine = StartCoroutine ( EofEnumerator ( ) ) ;
572577 }
573578
574579 return _eofUpdateSource ;
@@ -603,6 +608,12 @@ public void AddFrameCallback(Action callback, FrameTiming timing)
603608 break ;
604609
605610 case FrameTiming . EndOfFrame :
611+
612+ if ( _eofCoroutine == null )
613+ {
614+ _eofCoroutine = StartCoroutine ( EofEnumerator ( ) ) ;
615+ }
616+
606617 AddFrameCallback ( ref _eofUpdateActions , callback ) ;
607618 break ;
608619 }
@@ -612,6 +623,11 @@ public void AddFrameCallback(Action callback, FrameTiming timing)
612623
613624 #region MonoBehavoiur
614625
626+ private void Awake ( )
627+ {
628+ _eof = new WaitForEndOfFrame ( ) ;
629+ }
630+
615631 private void Update ( )
616632 {
617633 if ( _ops != null && _ops . Count > 0 )
@@ -840,7 +856,9 @@ private IEnumerator EofEnumerator()
840856 {
841857 InvokeFrameCallbacks ( _eofUpdateActions , this ) ;
842858 }
843- }
859+
860+ _eofCoroutine = null ;
861+ }
844862
845863 #endregion
846864 }
0 commit comments