@@ -105,7 +105,9 @@ public void Start(MonoBehaviour owner, STATE_ID startState, params STATE_ID[] ne
105105 public void ChangeState ( STATE_ID state )
106106 {
107107 if ( _debug )
108+ {
108109 Debug . Log ( $ "{ _owner . name } .FSM.ChangeState changeState:{ state } , wait:{ _waitQueue . ToStringCollection ( ) } ", _owner ) ;
110+ }
109111
110112 _commandQueue . Add ( new Command ( CommandType . Change , state ) ) ;
111113 }
@@ -125,7 +127,9 @@ public void FinishState()
125127 public void EnqueueToWaitQueue ( params STATE_ID [ ] nextStates )
126128 {
127129 if ( _waitQueue . Count > 10 )
130+ {
128131 Debug . LogWarning ( $ "{ _owner . name } _waitQueue.Count > 10, wait:{ _waitQueue . ToStringCollection ( ) } ", _owner ) ;
132+ }
129133 nextStates . Foreach ( state => _waitQueue . Add ( state ) ) ;
130134 }
131135
@@ -158,10 +162,14 @@ IEnumerator UpdateCoroutine()
158162 while ( true )
159163 {
160164 while ( _commandQueue . Count > 0 )
165+ {
161166 ProcessCommand ( _commandQueue . Dequeue ( ) ) ;
167+ }
162168
163169 if ( currentState == null && _waitQueue . Count > 0 )
170+ {
164171 OnStartState ( _waitQueue . Dequeue ( ) ) ;
172+ }
165173
166174 yield return null ;
167175 }
@@ -187,7 +195,9 @@ private void ProcessCommand(Command command)
187195 private void OnStartState ( STATE_ID stateID )
188196 {
189197 if ( _debug )
198+ {
190199 Debug . Log ( $ "{ _owner . name } .FSM.OnStartState.Entry current:{ currentStateID } , new:{ stateID } , wait:{ _waitQueue . ToStringCollection ( ) } ", _owner ) ;
200+ }
191201
192202 if ( _stateInstance . TryGetValue ( stateID , out TSTATE state ) == false )
193203 {
@@ -196,10 +206,14 @@ private void OnStartState(STATE_ID stateID)
196206 }
197207
198208 if ( state . Equals ( currentState ) )
209+ {
199210 return ;
211+ }
200212
201213 if ( _debug )
214+ {
202215 Debug . Log ( $ "{ _owner . name } .FSM.OnStartState.Execute current:{ currentStateID } , new:{ stateID } , wait:{ _waitQueue . ToStringCollection ( ) } ", _owner ) ;
216+ }
203217
204218 currentState ? . OnChangeState ( state ) ;
205219 state . OnAwake ( ) ;
@@ -212,10 +226,14 @@ private void OnStartState(STATE_ID stateID)
212226 private void OnFinishState ( )
213227 {
214228 if ( _debug )
229+ {
215230 Debug . Log ( $ "{ _owner . name } .FSM.OnFinishState current:{ currentStateID } , wait:{ _waitQueue . ToStringCollection ( ) } ") ;
231+ }
216232
217233 if ( _currentCoroutine != null )
234+ {
218235 _owner . StopCoroutine ( _currentCoroutine ) ;
236+ }
219237 currentState ? . OnFinishState ( ) ;
220238 currentState = null ;
221239 _currentStateID = default ;
0 commit comments