/// <summary> /// Change companion state machine state /// </summary> /// <param name="stateFlag">Flag of allowed state</param> private void ChangeState(StateFlag stateFlag) { if (this.States == null) { throw new InvalidStateException("State machine is not ready! Call setup first."); } if (!this.States.TryGetValue(stateFlag, out ICompanionState newState)) { throw new InvalidStateException($"Invalid state {stateFlag.ToString()}. Is state machine correctly set up?"); } if (this.currentState == newState) { return; } if (this.currentState != null) { this.currentState.Exit(); } newState.Entry(); this.currentState = newState; this.Monitor.Log($"{this.Name} changed state: {this.CurrentStateFlag.ToString()} -> {stateFlag.ToString()}"); this.CurrentStateFlag = stateFlag; }
/// <summary> /// Kills state machine current state behavior /// and forces empty behavior with RESET state flag. /// </summary> public void Kill() { var state = this.currentState; this.currentState = null; this.CurrentStateFlag = StateFlag.RESET; state?.Exit(); }
public void Dispose() { if (this.currentState != null) { this.currentState.Exit(); } this.States.Clear(); this.States = null; this.currentState = null; this.Companion = null; this.CompanionManager = null; this.ContentLoader = null; }
public void Dispose() { this.currentState?.Exit(); this.currentState = null; foreach (var state in this.States.Values.OfType <IDisposable>()) { state.Dispose(); } this.States.Clear(); this.States = null; this.Companion = null; this.CompanionManager = null; this.ContentLoader = null; }
public Companion() { State = new DefaultState(); }
public Companion(ICompanionState cstate) { State = cstate; }