private void Update() { Rotate(); var inputStatus = _state.GetInputStatus(); if (inputStatus.IsMoveForward) { MoveForward(); } if (inputStatus.IsMoveBackward) { MoveBackward(); } if (inputStatus.IsMoveLeft) { MoveLeft(); } if (inputStatus.IsMoveRight) { MoveRight(); } if (inputStatus.IsShot) { Debug.Log("ショット!"); } _state.Action(); Debug.Log("State : " + _state.GetStateType()); }
public virtual void ChangeState(ITransition transition) { if (transition == null) { throw new ArgumentNullException(nameof(transition), "Cannot change state with a null transition"); } var oldState = this.State; var newState = this.GetDestinationState(transition); if (newState == null) { throw new InvalidTransitionException(oldState, transition); } FireChanging(newState); // Exit old State try { State.Exit(transition); } catch (Exception e) { throw new StateFailedToExitException(oldState, transition, e); } // Change State State = newState; // Enter new State try { State.Enter(transition); } catch (Exception e) { throw new StateFailedToEnterException(oldState, transition, newState, e); } FireChanged(); State.Action(this); }
public virtual void ChangeState(IState newState) { if (newState == null) { throw new ArgumentNullException(nameof(newState), "Cannot change state to a null state"); } var oldState = this.State; FireChanging(newState); // Exit old State try { State?.Exit(); } catch (Exception e) { throw new StateFailedToExitException(oldState, null, e); } // Change State State = newState; // Enter new State try { State.Enter(); } catch (Exception e) { throw new StateFailedToEnterException(oldState, null, newState, e); } FireChanged(); State.Action(this); }
public virtual bool TryChangeState(ITransition transition) { if (transition == null) { return false; } var oldState = this.State; var newState = this.GetDestinationState(transition); if (newState == null) { return false; } FireChanging(newState); // Exit old State try { State.Exit(transition); } catch { return false; } // Change State State = newState; // Enter new State try { State.Enter(transition); } catch { State = oldState; return false; } FireChanged(); try { State.Action(this); } catch { return false; } return true; }