/// <summary> /// Execute the initial state and any subsequent states and transitions until there are no more /// states to execute. /// </summary> public IEnumerable Execute() { while (true) { // Execute the current state until it transitions or stops executing for ( var e = state.Execute().GetEnumerator(); transition == null && e.MoveNext(); ) { yield return(e.Current); } // Wait until the current state transitions while (transition == null) { yield return(null); } // Stop listening for the current state to transition // This prevents accidentally transitioning twice state.OnBeginExit -= HandleStateBeginExit; // There is no next state to transition to // This means the state machine is finished executing if (nextState == null) { break; } // Run the transition's exit process foreach (var e in transition.Exit()) { yield return(e); } state.EndExit(); // Switch state State = nextState; nextState = null; // Run the transition's enter process foreach (var e in transition.Enter()) { yield return(e); } transition = null; state.EndEnter(); } }
// 実行可能なIEnumerableを返す public IEnumerable Execute() { // ずっとぶん回す while (true) { for (var e = state.Execute().GetEnumerator(); transition == null && e.MoveNext();) { yield return(e.Current); } while (transition == null) { yield return(null); } state.OnBeginExit -= HandleStateBeginExit; if (nextState == null) { break; } // いまのステートが終わる時の演出 foreach (var e in transition.Exit()) { yield return(e); } state.EndExit(); // ステートの切り替え // BeginEnter()呼び出し State = nextState; nextState = null; // 新しいステートが始まるときの演出 foreach (var e in transition.Enter()) { yield return(e); } state.EndEnter(); transition = null; } }
public IEnumerable Execute() { while (true) { for (var e = state.Execute().GetEnumerator(); transition == null && e.MoveNext();) { yield return(e.Current); } while (transition == null) { yield return(null); } state.OnBeginExit -= HandleStateBeginExit; if (nextState == null) { break; } foreach (var e in transition.Exit()) { yield return(e); } state.EndExit(); State = nextState; nextState = null; foreach (var e in transition.Enter()) { yield return(e); } transition = null; state.EndEnter(); } }