private void Idle(ActionStateType action) { switch (action) { case ActionStateType.Start: { _acceleration = 0; _speed = 0; _animator.SetBool(_isDrivingParameterName, false); break; } case ActionStateType.Update: { if (Input.GetKey(KeyCode.UpArrow)) { _stateMachine.ChangeState <float>(_drivingState, 1); } else if (Input.GetKey(KeyCode.DownArrow)) { _stateMachine.ChangeState <float>(_drivingState, -1); } break; } } }
void Update() { #if UNITY_EDITOR if (isDummy) { return; } if (actorController == null) { return; // prevents error spam after editing a script } #endif actorController.UpdateCommands(); ActionStateType nextAction = actionState.UpdateState(); if (nextAction != ActionStateType.NONE) { if (!actionStateLookup.TryGetValue(nextAction, out IActionState newAction)) { Debug.Log(this.name + " could not find actionState for " + nextAction.ToString()); } else { ActionStateType prevAction = actionState.ExitState(nextAction); actionState = newAction; actionState.EnterState(prevAction); currentActionState = nextAction; } } }
public void EnterState(ActionStateType previousState) { actor.SetAnimator(Actor.IsShootingHash, true); spawnBullet = true; firstShot = true; timeSinceShoot = 0f; }
/// <summary> /// A hack to get button input in the elevator. /// </summary> public void EnterElevator() { ActionStateType nextAction = ActionStateType.ELEVATOR; if (!actionStateLookup.TryGetValue(nextAction, out IActionState newAction)) { Debug.Log(this.name + " could not find actionState for " + nextAction.ToString()); } else { ActionStateType prevAction = actionState.ExitState(nextAction); actionState = newAction; actionState.EnterState(prevAction); currentActionState = nextAction; } }
private void LoosingSpeed(ActionStateType action, float directionMultiplayer) { switch (action) { case ActionStateType.Start: { _animator.SetBool(_isDrivingParameterName, true); break; } case ActionStateType.Update: { if (Input.GetKey(KeyCode.UpArrow) && directionMultiplayer > 0 || Input.GetKey(KeyCode.DownArrow) && directionMultiplayer < 0) { _stateMachine.ChangeState(_drivingState, directionMultiplayer); } if (Math.Abs(_acceleration) > 0) { _acceleration -= AccelerationPower * directionMultiplayer; } else { _acceleration = 0; } if (Input.GetKey(KeyCode.DownArrow) && directionMultiplayer > 0 || Input.GetKey(KeyCode.UpArrow) && directionMultiplayer < 0) { _speed -= BreakDeAcceleration * directionMultiplayer; } _speed -= DeAcceleration * directionMultiplayer; if (_speed * directionMultiplayer <= 0f) { _speed = 0f; _stateMachine.ChangeState(_idleState); } break; } } }
protected void SetBlockState(short blockIndex, ActionStateType act) { bool ok = false; var list = new ArrayList(); for (short i = 0; i < BlockCount; i++) { if (blockIndex != -1 && i == blockIndex) { i = blockIndex; ok = true; } var bs = GetBlock(i); if (bs != null) { bs.BlockRunState = act; if (bs.AssistThread != null && bs.AssistThread.IsAlive && act == ActionStateType.Stop) { list.Add(bs.AssistThread); } } if (ok) { break; } } foreach (var item in list) { var t = (Thread)item; try { t.Abort(); } catch (ThreadStateException) { } } }
private void Driving(ActionStateType action, float directionMultiplayer) { switch (action) { case ActionStateType.Start: { _animator.SetBool(_isDrivingParameterName, true); break; } case ActionStateType.Update: { if (Input.GetKey(KeyCode.UpArrow) == false && directionMultiplayer > 0 || Input.GetKey(KeyCode.DownArrow) == false && directionMultiplayer < 0) { _stateMachine.ChangeState(_loosingSpeedState, directionMultiplayer); } if (Math.Abs(_acceleration) < MaxAcceleration) { _acceleration += AccelerationPower * directionMultiplayer; } else { _acceleration = MaxAcceleration * directionMultiplayer; } if (Math.Abs(_speed) < MaxSpeed) { _speed += _acceleration; } else { _speed = MaxSpeed * directionMultiplayer; } break; } } }
public ActionStateType ExitState(ActionStateType nextState) { return(actionStateType); }
public void EnterState(ActionStateType previousState) { }
public void Awake() { sprite = GetComponent <SpriteRenderer>(); actorPhysics = GetComponent <IActorPhysics>(); if (!animator) { animator = GetComponent <Animator>(); if (!animator) { Debug.LogWarning("No animator found for " + gameObject.name); } } actionStateLookup = new Dictionary <ActionStateType, IActionState>(); movementStateLookup = new Dictionary <MovementStateType, IMovementState>(); if (!standingState) { standingState = GetComponentInChildren <StandingState>(); } if (standingState) { standingState.SetActor(this); movementStateLookup.Add(MovementStateType.STANDING, standingState); } if (!duckingState) { duckingState = GetComponentInChildren <KneelingState>(); } if (duckingState) { duckingState.SetActor(this); movementStateLookup.Add(MovementStateType.KNEELING, duckingState); } if (!walkingState) { walkingState = GetComponentInChildren <WalkingState>(); } if (walkingState) { walkingState.SetActor(this); movementStateLookup.Add(MovementStateType.WALKING, walkingState); } if (stairsState) { stairsState.SetActor(this); movementStateLookup.Add(MovementStateType.STAIRS, stairsState); } if (!airbornState) { airbornState = GetComponentInChildren <FallingState>(); } if (airbornState) { airbornState.SetActor(this); movementStateLookup.Add(MovementStateType.FALLING, airbornState); } if (!jetpackState) { jetpackState = GetComponentInChildren <JetpackState>(); } if (jetpackState) { jetpackState.SetActor(this); movementStateLookup.Add(MovementStateType.JETPACK, jetpackState); } elevatorState = GetComponentInChildren <ElevatorState>(); if (elevatorState) { elevatorState.SetActor(this); movementStateLookup.Add(MovementStateType.ELEVATOR, elevatorState); actionStateLookup.Add(ActionStateType.ELEVATOR, elevatorState); } NoActionState awaitingState = new NoActionState(); awaitingState.SetActor(this); actionStateLookup.Add(ActionStateType.AWAITING_ACTION, awaitingState); if (!shootingState) { shootingState = GetComponentInChildren <ShootingState>(); } if (shootingState) { shootingState.SetActor(this); actionStateLookup.Add(ActionStateType.SHOOT, shootingState); } currentMovementState = MovementStateType.FALLING; movementState = airbornState; currentActionState = ActionStateType.AWAITING_ACTION; actionState = actionStateLookup[ActionStateType.AWAITING_ACTION]; }
public ActionStateType ExitState(ActionStateType nextState) { actor.SetAnimator(Actor.IsShootingHash, false); return(actionStateType); }