protected override FSM BuildStateMachine() { STATE_MOVING = new FSM.State(OnMovingUpdate) { Name = "Moving", OnExit = StopCar }; STATE_AIMING = new TimedState(3.0f, OnAimUpdate) { Name = "Aiming", OnEnter = StartAiming }; STATE_SHOOTING = new WaitState(2, STATE_MOVING) { Name = "Shooting", OnEnter = Shoot, OnExit = SelectRandomDirection }; return(new FSM(STATE_NO_ACTION)); }
public void AbilityTransition(Ability ability, float abilityLength, string overrideAnimation) { if (ability == null) //defensive { return; } else if (ability.IsCharged) { Transition(FSMState.ChargingAbility, overrideAnimation); } else { Transition(FSMState.CastingAbility, overrideAnimation); } TimedState timedState = (TimedState)Current; timedState.OverrideStateLength(abilityLength); }
protected override FSM BuildStateMachine() { STATE_IDLE = new FSM.State(OnIdleUpdate, OnIdleStart) { Name = "Idle" }; STATE_RUN = new FSM.State(OnRunUpdate, OnRunStart, OnRunEnd) { Name = "Run" }; STATE_JUMP = new FSM.State(OnJumpUpdate, OnJumpStart, OnJumpEnded) { Name = "Jump" }; STATE_FALL = new FSM.State(OnFallUpdate, OnFallStart, OnFallEnd) { Name = "Fall" }; STATE_HURT = new TimedState(HitDuration, OnHurtUpdate) { Name = "Hurt", OnEnter = OnHurtEnter, OnExit = OnHurtExit }; STATE_DASH = new FSM.State(OnDashUpdate, OnDashStart, OnDashEnded) { Name = "Dash" }; STATE_VULNERABLE = new FSM.State(); STATE_HURT_INVINCIBLE = new WaitState(HitInvencibility, STATE_VULNERABLE) { Name = "Hurt_Invincible", OnEnter = OnHurtInvincibleEnter, OnExit = OnHurtInvincibleExit }; invencibilityMachine = new FSM(STATE_VULNERABLE); return(new FSM(STATE_IDLE)); }
/// <summary> /// Starts a state, and returns a token that can be used to stop it again. /// </summary> /// <param name="stateData">Custom state data. This is useful in cases /// where all the active states needs to be examined. For example, this data /// can be used to identify states externally.</param> /// <param name="currentTime">The current time.</param> /// <param name="maxTime">The maximum amount of time this state should survive past the current time.</param> /// <param name="onTimeOut">An action to call when this state times out.</param> /// <returns>A token that wraps the custom state data and can be used to stop /// the state started with this method.</returns> /// <remarks>For a state to time out, it is necessary for the Update method to /// be called regularly (for example, in a MonoBehaviours Update method).</remarks> public IStateToken <TStateData> StartState( TStateData stateData, float currentTime, float maxTime, Action onTimeOut) { var state = new TimedState { stateData = stateData, timeData = new TimeData() { startTime = currentTime, maxTime = maxTime, onTimeOut = onTimeOut } }; var token = tracker.StartState(state); return(new TimeStateWrapper { token = token }); }
///<exclude/> public bool Equals(TimedState other) { if (ReferenceEquals(null, other)) return false; if (ReferenceEquals(this, other)) return true; return other._Tm.Equals(_Tm) && other._Data.Equals(_Data); }