Skip to content

Commit 9ed7cbf

Browse files
committed
Wait enter
1 parent 69f21e1 commit 9ed7cbf

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

Runtime/AsyncStateMachine.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ public AsyncStateMachine(CancellationToken cancelToken, bool nonUpdate = false)
6969
private CancellationTokenSource? _onUpdateCancellation = new CancellationTokenSource();
7070
private CancellationToken _disposedToken;
7171
private MonoBehaviour _monoBehaviourObject;
72+
private bool _waitEnter = false;
7273
private bool _nonUpdate = false;
7374

7475

@@ -239,9 +240,11 @@ public async UniTask ChangeStateAsync(TStateKey key)
239240

240241
if (m_currentState != null)
241242
{
243+
_waitEnter = true;
242244
currentTask = m_currentState.OnStateEnter();
243245
await currentTask.Value;
244246
currentTask = null;
247+
_waitEnter = false;
245248
}
246249

247250
this._mCurState = key;
@@ -295,9 +298,14 @@ private async UniTask UpdateState()
295298
/// FSM 로직을 업데이트 타이밍에 비동기로 처리합니다.
296299
/// </summary>
297300
private async UniTaskVoid StartUpdateLoopAsync(CancellationToken token)
298-
{
301+
{
302+
299303
await foreach (var _ in UniTaskAsyncEnumerable.EveryUpdate().WithCancellation(token))
300-
{
304+
{
305+
if (_waitEnter)
306+
{
307+
continue;
308+
}
301309
if (_monoBehaviourObject != null)
302310
{
303311
if (_monoBehaviourObject.gameObject.activeSelf && _monoBehaviourObject.enabled)

0 commit comments

Comments
 (0)