private void StopActiveState() { _stateExecution?.Dispose(); ActiveState?.Exit(); ActiveState = null; Context = null; _stateExecution = null; }
// Change State via State Reference public void ChangeState(State toState) { if (ActiveState != null) { ActiveState.Exit(); } if (LastState != null && !LastState.Equals(toState)) { LastState = ActiveState; } ActiveState = toState; ActiveState.Enter(); }
/// <summary> /// Instantly changes to the target state /// </summary> /// <param name="name">The name / identifier of the active state</param> void ChangeState(string name) { State <T> newState = GetState(name); ActiveState?.Exit(); PreviousState = ActiveState?.name ?? ""; ActiveState = newState; ActiveState.Enter(); if (fromToTransitions.TryGetValue(name, out List <FromToTransition <T> > newActiveTransitions)) { activeStateTransitions = newActiveTransitions; foreach (FromToTransition <T> transition in activeStateTransitions) { transition.OnEnterFromState(); } } else { activeStateTransitions = System.Array.Empty <Transition <T> >(); } }
/// <inheritdoc /> public void SwitchState(IState newState) { if (ActiveState != null) { ActiveState.SwitchState(null); ActiveState.Exit(); ActiveState.OnLeafStateChanged -= InvokeLeafStateChange; } var oldState = ActiveState; ActiveState = newState; if (newState != null) { newState.Enter(); newState.OnLeafStateChanged += InvokeLeafStateChange; } if (oldState != newState) { InvokeLeafStateChange(newState?.ActiveLeafState); } }
protected override void OnExit() { ActiveState.Exit(); }