private void SphereCollide(Collision collision) { if (_stateMachine.CurrentState.GetType() == typeof(SmashState)) { SmashState smash = (SmashState)_stateMachine.CurrentState; string tag = collision.gameObject.tag;; smash.TargetTag = tag; IsSmashing = false; if (tag == "Ground") { _cameraShaker.ShakeOnce(5f, 2f, .1f, 1f); SoundManager.Instance.PlaySound(SoundManager.Sound.Smash); } } }
public ControlSpMovement(ref IMovementAndMeleeCombatLogic input, ref IMove characterController , ref Animator animator, ref IRangedCombatLogic rangedLogic, ref IInvertoryLogic invertoryLogic, ref ISpCameraFollow camera) { this.rangedInput = rangedLogic; this.rangedInput.InputChanged += RangedInput_InputChanged; this.invertoryInput = invertoryLogic; this.spCamera = camera; // Movement FSM setup this.movementAndMeleeControl = input; this.fSMSpMovement = new FSMachineSpacemarineMove(EMovementID.Walking, ref this.movementAndMeleeControl, true); WalkState walkState = new WalkState(true, 2.0f, ref characterController, ref this.movementAndMeleeControl, EMovementID.Walking, ref animator); RunState runState = new RunState(false, 5.0f, ref characterController, ref this.movementAndMeleeControl, EMovementID.Running, ref animator); SmashState smashState = new SmashState(false, 6.0f, 1.25f, ref characterController, ref this.movementAndMeleeControl, EMovementID.Smashing, ref animator); FallState fallState = new FallState(2.0f, -Physics.gravity.y * Vector3.down, true, ref characterController, ref this.movementAndMeleeControl, EMovementID.Falling, ref animator); LandState landState = new LandState(0.75f, false, ref input, ref characterController, EMovementID.Landing); this.fSMSpMovement.AddState(walkState); this.fSMSpMovement.AddState(runState); this.fSMSpMovement.AddState(smashState); this.fSMSpMovement.AddState(fallState); this.fSMSpMovement.AddState(landState); this.fSMSpMovement.SetDefaultState(walkState); this.fSMSpMovement.StateChanged += FSMSpMovement_StateChanged; // Melee FSM machine setup AttackState attackState = new AttackState(false, EMeleeAttackID.Attacking, ref this.movementAndMeleeControl, ref invertoryLogic, ref animator); MeleeIdle meleeIdle = new MeleeIdle(true, EMeleeAttackID.Idle, ref this.movementAndMeleeControl); this.fSMSpCombat = new FSMCombatSpacemarine(true, EMeleeAttackID.Idle, ref this.movementAndMeleeControl, ref invertoryLogic); this.fSMSpCombat.AddState(attackState); this.fSMSpCombat.AddState(meleeIdle); this.fSMSpCombat.SetDefaultState(meleeIdle); //Ranged FSM setup IHoldWeapon holdWeaponInfo = new HoldPistol(5.0f); IRangedState holdState = new HoldState(true, ref rangedLogic, ERangedAttackID.Hold, ref holdWeaponInfo, ref animator, ref invertoryInput); IRangedShootState shootState = new ShootState(true, ERangedAttackID.Shoot, ref rangedLogic, ref animator, ref invertoryLogic); IRangedState reloadState = new ReloadState(true, ref rangedLogic, ERangedAttackID.Reload, ref invertoryLogic, ref animator); IRangedState laydownState = new LaydownState(true, ref rangedLogic, ERangedAttackID.LayDown, ref invertoryLogic); this.fSMSpRangedCombat = new FSMRangedSpacemarine(true, ERangedAttackID.LayDown, ref rangedLogic, ref invertoryLogic); this.fSMSpRangedCombat.AddState(holdState); this.fSMSpRangedCombat.AddState(reloadState); this.fSMSpRangedCombat.AddState(shootState); this.fSMSpRangedCombat.AddState(laydownState); this.fSMSpRangedCombat.SetDefaultState(laydownState); this.fSMSpRangedCombat.StateChanged += FSMSpRangedCombat_StateChanged; // Invertory Setup InvertoryIdle invertoryIdleState = new InvertoryIdle(true, ref invertoryLogic); InvertorySwitch invertorySwitchState = new InvertorySwitch(true, ref invertoryLogic, ref animator); this.fSMInvertory = new FSMInvertory(EInvertoryStateID.None, ref invertoryLogic); this.fSMInvertory.AddState(invertoryIdleState); this.fSMInvertory.AddState(invertorySwitchState); this.fSMInvertory.SetDefaultState(invertoryIdleState); this.fSMInvertory.StateChanged += FSMInvertory_StateChanged; if (invertoryLogic.HasInputModel) { this.spCamera.ObjectRotator.CanRotate = !invertoryLogic.InputInfo.CurrentWeapons.IsMeleeEquipment; this.spCamera.IsMeleeViewEnabled = !invertoryLogic.InputInfo.CurrentWeapons.IsMeleeEquipment; } else { this.spCamera.IsMeleeViewEnabled = false; } }