public void Resume() { if (!HasStarted) { throw new System.InvalidOperationException("Can't resume an uninitiated State Machine, call Start() first."); } if (IsRunning) { return; } if (CurrentCoroutine != null) { if (!CurrentCoroutine.HasEnded) { CurrentCoroutine.Resume(); if (!Coroutines.Instance.Has(CurrentCoroutine)) { Coroutines.Instance.Start(CurrentCoroutine); } } else { CurrentCoroutine = null; } } IsRunning = true; }
public void Pause() { if (!HasStarted) { throw new System.InvalidOperationException("Can't pause an uninitiated State Machine, call Start() first."); } if (!IsRunning) { return; } if (CurrentCoroutine != null) { if (CurrentCoroutine.HasEnded) { CurrentCoroutine = null; } else { CurrentCoroutine.Pause(); } } IsRunning = false; }
private void UpdateState() { ProcessStateLeave(CurrentState.OnLeave); CurrentCoroutine?.Stop(); PreviousState = CurrentState; CurrentState = NextState; NextState = null; if (CurrentState == null) { return; } ProcessStateEnter(CurrentState.OnEnter); CurrentCoroutine = Coroutines.Instance.Start(ProcessStateUpdate(CurrentState.OnUpdate)); }
public void Stop() { if (!HasStarted) { return; } NextState = PreviousState = CurrentState = StartState = null; if (CurrentCoroutine != null) { Coroutines.Instance.Remove(CurrentCoroutine); CurrentCoroutine.Stop(); CurrentCoroutine = null; } HasStarted = IsRunning = false; }
public override void Update(DwarfTime gameTime) { CompositeLibrary.Update(); MainWindow.LocalBounds = new Rectangle(EdgePadding, EdgePadding, Game.GraphicsDevice.Viewport.Width - EdgePadding * 2, Game.GraphicsDevice.Viewport.Height - EdgePadding * 2); Input.Update(); GUI.Update(gameTime); if (CurrentAction != null) { if (CurrentCoroutine == null) { CurrentCoroutine = CurrentAction.Action(); CurrentEnumerator = CurrentCoroutine.GetEnumerator(); } if (CurrentCoroutine != null) { SpeechNode node = CurrentEnumerator.Current; if (node != null) { Transition(node); CurrentCoroutine = null; CurrentAction = null; } else { if (!CurrentEnumerator.MoveNext()) { CurrentCoroutine = null; CurrentAction = null; CurrentEnumerator = null; Transition(DialougeTree); } } } } base.Update(gameTime); }