public override void OnAnimationEvent(AnimationEvent aniEvent) { if (aniEvent.animatorStateInfo.shortNameHash == Player.StateNameHash.swapWeapon) { if (aniEvent.stringParameter.Equals(LocalPlayerController.AniEventName.swap)) { player.ChangeWeapon(nextWeapon); if (nextWeapon == WeaponType.Pistol) { controller.ClearTarget(); } } else if (aniEvent.stringParameter.Equals(LocalPlayerController.AniEventName.done)) { player.UpperSuitLowerAnimation(); nextWeapon = WeaponType.Empty; upperAction = UpperAction.Empty; } } //else if(aniEvent.animatorStateInfo.shortNameHash == Player.StateNameHash.move) { if (aniEvent.stringParameter.Equals(LocalPlayerController.AniEventName.step)) { TimeSpan span = DateTime.Now - lastStepTime; if (span.TotalMilliseconds > 150f) { int r = UnityEngine.Random.Range(1, 4); AudioClip clip = (AudioClip)Resources.Load(StringAssets.soundPath + "foot" + r, typeof(AudioClip)); player.audioSource.PlayOneShot(clip, 0.5f); lastStepTime = DateTime.Now; } } } }
/// <summary> /// plays an upper animation according to action. /// </summary> /// <param name="action">upper action</param> /// <param name="startTime">start time of animation</param> public void PlayUpperAction(UpperAction action, float startTime) { AnimPlayMode playMode = AnimPlayMode.Repeat; float blendTime = 0.0f; switch (action) { case UpperAction.Idle: { blendTime = 0.5f; } break; case UpperAction.Run: { blendTime = 0.3f; } break; case UpperAction.Damage: { playMode = AnimPlayMode.Once; blendTime = 0.2f; } break; case UpperAction.WeaponChange: { playMode = AnimPlayMode.Once; blendTime = 0.2f; } break; case UpperAction.ForwardNonFire: case UpperAction.LeftNonFire: case UpperAction.RightNonFire: { playMode = AnimPlayMode.Once; blendTime = 0.5f; } break; case UpperAction.ForwardMachineGunFire: case UpperAction.ForwardShotgunFire: case UpperAction.ForwardHandgunFire: case UpperAction.LeftMachineGunFire: case UpperAction.LeftShotgunFire: case UpperAction.LeftHandgunFire: case UpperAction.RightMachineGunFire: case UpperAction.RightShotgunFire: case UpperAction.RightHandgunFire: { playMode = AnimPlayMode.Once; blendTime = 0.5f; } break; case UpperAction.ReloadMachineGun: case UpperAction.ReloadShotgun: case UpperAction.ReloadHandgun: { playMode = AnimPlayMode.Once; blendTime = 0.5f; } break; case UpperAction.ForwardDead: case UpperAction.BackwardDead: case UpperAction.LeftDead: case UpperAction.RightDead: { playMode = AnimPlayMode.Once; blendTime = 0.2f; } break; case UpperAction.BoosterPrepare: case UpperAction.BoosterFinish: case UpperAction.BoosterActive: case UpperAction.BoosterBreak: case UpperAction.BoosterLeftTurn: case UpperAction.BoosterRightTurn: { playMode = AnimPlayMode.Once; blendTime = 0.2f; } break; default: throw new NotSupportedException("Not supported an animation"); } // Play the upper animation PlayAnimation(indexUpperAnimation[(int)action], startTime, blendTime, this.defaultAnimationScaleFactor, playMode); this.currentUpperAction = action; this.prepareUpperAction = UpperAction.Unknown; this.isOverwriteUpperAction = false; }
/// <summary> /// plays an upper animation according to action. /// </summary> /// <param name="action">upper action</param> public void PlayUpperAction(UpperAction action) { PlayUpperAction(action, 0.0f); }
/// <summary> /// plays an animation of not firing due to having no ammunition. /// </summary> public void ActionNonFire() { // Left moving fire if (this.moveDirection.X < 0.0f) { // Forward left moving fire if (this.moveDirection.Z > 0.0f) { if( this.prepareUpperAction != UpperAction.LeftNonFire) this.prepareUpperAction = UpperAction.LeftNonFire; } // Backward left moving fire else if (this.moveDirection.Z < 0.0f) { if (this.prepareUpperAction != UpperAction.RightNonFire) this.prepareUpperAction = UpperAction.RightNonFire; } // Left moving fire else { if (this.prepareUpperAction != UpperAction.LeftNonFire) this.prepareUpperAction = UpperAction.LeftNonFire; } } // Right moving Fire else if (this.moveDirection.X > 0.0f) { // Forward right moving fire if (this.moveDirection.Z > 0.0f) { if (this.prepareUpperAction != UpperAction.RightNonFire) this.prepareUpperAction = UpperAction.RightNonFire; } // Backward right moving fire else if (this.moveDirection.Z < 0.0f) { if (this.prepareUpperAction != UpperAction.LeftNonFire) this.prepareUpperAction = UpperAction.LeftNonFire; } // Right moving fire else { if (this.prepareUpperAction != UpperAction.RightNonFire) this.prepareUpperAction = UpperAction.RightNonFire; } } // Forward or Backward moving Fire else { if (this.prepareUpperAction != UpperAction.ForwardNonFire) this.prepareUpperAction = UpperAction.ForwardNonFire; } }
/// <summary> /// determines an moving animation according to velocity. /// </summary> /// <param name="gameTime"></param> /// <param name="moveDirection"></param> public void ActionMovement(GameTime gameTime, Vector3 moveDirection) { bool doMove = true; // Forward if (moveDirection.Z > 0.0f) { // Move Left forward if (moveDirection.X < 0.0f) { // Player change root axis this.rootRotationAngle = 35.0f; } // Move Right forward else if (moveDirection.X > 0.0f) { // Player change root axis this.rootRotationAngle = -35.0f; } // Forward else { this.rootRotationAngle = 0.0f; } if (IsFiring || IsReloading || IsWeaponChanging || IsTryEmptyWeapon) { if (this.CurrentLowerAction != LowerAction.Walk) this.prepareLowerAction = LowerAction.Walk; } else { if (this.CurrentLowerAction != LowerAction.Run) this.prepareLowerAction = LowerAction.Run; } if (this.CurrentUpperAction != UpperAction.Run && !IsFiring && !IsReloading && !IsWeaponChanging && !IsTryEmptyWeapon && !IsDead) { this.prepareUpperAction = UpperAction.Run; } } // Backward else if (moveDirection.Z < 0.0f) { // Move Left backward if (moveDirection.X < 0.0f) { // Player change root axis this.rootRotationAngle = -30.0f; } // Move Right backward else if (moveDirection.X > 0.0f) { // Player change root axis this.rootRotationAngle = 30.0f; } // Backward else { // Player change root axis this.rootRotationAngle = 0.0f; } if (this.CurrentLowerAction != LowerAction.BackwardWalk) this.prepareLowerAction = LowerAction.BackwardWalk; if (this.CurrentUpperAction != UpperAction.Idle && !IsFiring && !IsReloading && !IsTryEmptyWeapon && !IsWeaponChanging && !IsDead) { this.prepareUpperAction = UpperAction.Idle; } } else { // Move to Left if (moveDirection.X < 0.0f) { // Player change root axis this.rootRotationAngle = 65.0f; if (IsFiring || IsReloading || IsWeaponChanging || IsTryEmptyWeapon) { if (this.CurrentLowerAction != LowerAction.Walk) this.prepareLowerAction = LowerAction.Walk; } else { if (this.CurrentLowerAction != LowerAction.Run) this.prepareLowerAction = LowerAction.Run; } if (this.CurrentUpperAction != UpperAction.Run && !IsFiring && !IsReloading && !IsTryEmptyWeapon && !IsWeaponChanging && !IsDead) { this.prepareUpperAction = UpperAction.Run; } } // Move to Right else if (moveDirection.X > 0.0f) { // Player change root axis this.rootRotationAngle = -65.0f; if (IsFiring || IsReloading || IsWeaponChanging || IsTryEmptyWeapon) { if (this.CurrentLowerAction != LowerAction.Walk) this.prepareLowerAction = LowerAction.Walk; } else { if (this.CurrentLowerAction != LowerAction.Run) this.prepareLowerAction = LowerAction.Run; } if (this.CurrentUpperAction != UpperAction.Run && !IsFiring && !IsReloading && !IsTryEmptyWeapon && !IsWeaponChanging && !IsDead) { this.prepareUpperAction = UpperAction.Run; } } // Move Stop else { doMove = false; if (this.CurrentLowerAction == LowerAction.Run || this.CurrentLowerAction == LowerAction.Walk || this.CurrentLowerAction == LowerAction.BackwardWalk) { this.prepareLowerAction = LowerAction.Idle; } if (this.CurrentUpperAction != UpperAction.Idle && !IsFiring && !IsReloading && !IsTryEmptyWeapon && !IsWeaponChanging && !IsDead) { this.prepareUpperAction = UpperAction.Idle; } // Player change root axis this.rootRotationAngle = 0.0f; this.moveElapsedTime = 0.0f; } } if (doMove) { // Play the moving sound if (this.CurrentLowerAction == LowerAction.Run) { if (this.moveElapsedTime == 0.0f) { if (GameSound.IsPlaying(soundWalk)) GameSound.Stop(soundWalk); if (GameSound.IsPlaying(soundRun)) GameSound.Stop(soundRun); soundRun = GameSound.Play3D(SoundTrack.PlayerRun, RobotGameGame.SinglePlayer); } // Calculate run animation playing time for run sound if (this.runDurationTime > this.moveElapsedTime) { this.moveElapsedTime += (float)gameTime.ElapsedGameTime.TotalSeconds; } else { this.moveElapsedTime = 0.0f; } } else if (this.CurrentLowerAction == LowerAction.Walk) { if (this.moveElapsedTime == 0.0f) { if (GameSound.IsPlaying(soundWalk)) GameSound.Stop(soundWalk); if (GameSound.IsPlaying(soundRun)) GameSound.Stop(soundRun); soundWalk = GameSound.Play3D(SoundTrack.PlayerWalk, RobotGameGame.SinglePlayer); } // Calculate walk animation playing time for run sound if (this.walkDurationTime > this.moveElapsedTime) { this.moveElapsedTime += (float)gameTime.ElapsedGameTime.TotalSeconds; } else { this.moveElapsedTime = 0.0f; } } else if (this.CurrentLowerAction == LowerAction.BackwardWalk) { if (this.moveElapsedTime == 0.0f) { if (GameSound.IsPlaying(soundWalk)) GameSound.Stop(soundWalk); if (GameSound.IsPlaying(soundRun)) GameSound.Stop(soundRun); soundWalk = GameSound.Play3D(SoundTrack.PlayerWalk, RobotGameGame.SinglePlayer); this.moveElapsedTime = 0.0f; } // Calculate walk animation playing time for run sound if (this.walkDurationTime > this.moveElapsedTime) { this.moveElapsedTime += (float)gameTime.ElapsedGameTime.TotalSeconds; } else { this.moveElapsedTime = 0.0f; } } } else { // Stop the move sound if (GameSound.IsPlaying(soundRun)) GameSound.Stop(soundRun); if (GameSound.IsPlaying(soundWalk)) GameSound.Stop(soundWalk); this.moveElapsedTime = 0.0f; } }
/// <summary> /// an animation of booster in progress. /// </summary> protected void ActionBoosterActive() { this.isActiveBooster = true; this.isDelayBooster = false; this.prepareLowerAction = LowerAction.BoosterActive; this.prepareUpperAction = UpperAction.BoosterActive; if (!GameSound.IsPlaying(soundBooster)) soundBooster = GameSound.Play3D(SoundTrack.PlayerBooster, RobotGameGame.SinglePlayer); Matrix fixedAxis = Matrix.CreateRotationX(MathHelper.ToRadians(-90.0f)); int count = 1; if (this.UnitType == UnitTypeId.Mark || this.UnitType == UnitTypeId.Yager) count = 2; // Play the booster flash particle on the backpack for (int i = 0; i < count; i++) { int index = -1; if (i == 0) index = this.indexLeftBoosterDummy; else index = this.indexRightBoosterDummy; particleBoosterOn[i] = GameParticle.PlayParticle( ParticleType.BoosterOn, BoneTransforms[index], fixedAxis); } // Booster slide particle on the ground particleBoosterGround[0] = GameParticle.PlayParticle( ParticleType.BoosterGround, BoneTransforms[indexLeftFootDummy], fixedAxis); particleBoosterGround[1] = GameParticle.PlayParticle( ParticleType.BoosterGround, BoneTransforms[indexRightFootDummy], fixedAxis); // vibrate a camera and controller if (FrameworkCore.CurrentCamera.FirstCamera is FollowCamera) { InputComponent input = FrameworkCore.InputManager.GetInputComponent(this.PlayerIndex); input.SetGamePadVibration(0.3f, 0.5f, 0.5f); } }
/// <summary> /// an animation of getting ready before booster. /// </summary> protected void ActionBoosterPrepare() { this.isActiveBooster = true; this.isDelayBooster = true; this.actionElapsedTime = 0.0f; this.boosterWaveEffectTime = 0.0f; this.prepareLowerAction = LowerAction.BoosterPrepare; this.prepareUpperAction = UpperAction.BoosterPrepare; if (!GameSound.IsPlaying(soundBoosterPrepare)) { soundBoosterPrepare = GameSound.Play3D(SoundTrack.PlayerPrepareBooster, RobotGameGame.SinglePlayer); } int count = 1; if (this.UnitType == UnitTypeId.Mark || this.UnitType == UnitTypeId.Yager) count = 2; // Play the booster prepare particle on the backpack for (int i = 0; i < count; i++) { int index = -1; if( i == 0) index = this.indexLeftBoosterDummy; else index = this.indexRightBoosterDummy; particleBoosterPrepare[i] = GameParticle.PlayParticle( ParticleType.BoosterPrepare, BoneTransforms[index], Matrix.CreateRotationX(MathHelper.ToRadians(-90.0f))); } }
/// <summary> /// takes the reload action. /// </summary> /// <param name="weapon">current weapon</param> /// <returns></returns> public override bool ActionReload(GameWeapon weapon) { // If weapon reloaded, action reload if (CurrentWeapon.IsPossibleToReload()) { CurrentWeapon.Reload(this.UnitType); switch (this.CurrentWeapon.WeaponType) { case WeaponType.PlayerMachineGun: { this.prepareUpperAction = UpperAction.ReloadMachineGun; } break; case WeaponType.PlayerShotgun: { this.prepareUpperAction = UpperAction.ReloadShotgun; } break; case WeaponType.PlayerHandgun: { this.prepareUpperAction = UpperAction.ReloadHandgun; } break; } RobotGameGame.CurrentStage.DisableControlHelper( (int)this.PlayerIndex, 0); return true; } return false; }
/// <summary> /// an animation at the end of booster. /// </summary> public void ActionBoosterFinish() { this.isActiveBooster = true; this.isDelayBooster = true; this.actionElapsedTime = 0.0f; this.boosterWaveEffectTime = 0.0f; this.prepareLowerAction = LowerAction.BoosterFinish; this.prepareUpperAction = UpperAction.BoosterFinish; // Stop the booster sound if (GameSound.IsPlaying(soundBoosterPrepare)) GameSound.Stop(soundBoosterPrepare); if (GameSound.IsPlaying(soundBooster)) GameSound.Stop(soundBooster); // Stop the booster particle BoosterParticleStop(); // Vibrate the camera and controller if (FrameworkCore.CurrentCamera.FirstCamera is FollowCamera) { InputComponent input = FrameworkCore.InputManager.GetInputComponent(this.PlayerIndex); input.SetGamePadVibration(boosterFinishDurationTime / 2, 0.15f, 0.15f); } }
/// <summary> /// takes the destruction action. /// Plays different destroy animation according to the attack direction. /// </summary> /// <param name="attackerPosition"></param> public override void ActionDead(Vector3 attackerPosition) { Vector3 dir = Vector3.Normalize(attackerPosition - Position); float FrontDot = Vector3.Dot(Direction, dir); float RightDot = Vector3.Dot(Right, dir); if (FrontDot > 0.5f) { // Hit from front this.prepareLowerAction = LowerAction.BackwardDead; this.prepareUpperAction = UpperAction.BackwardDead; } else if (FrontDot < -0.5f) { // Hit from back this.prepareLowerAction = LowerAction.ForwardDead; this.prepareUpperAction = UpperAction.ForwardDead; } else if (RightDot >= 0.0f) { // Hit from right this.prepareLowerAction = LowerAction.LeftDead; this.prepareUpperAction = UpperAction.LeftDead; } else if (RightDot < 0.0f) { // Hit from left this.prepareLowerAction = LowerAction.RightDead; this.prepareUpperAction = UpperAction.RightDead; } // Stop the sound if (GameSound.IsPlaying(soundRun)) GameSound.Stop(soundRun); if (GameSound.IsPlaying(soundWalk)) GameSound.Stop(soundWalk); CurrentWeapon.StopFireSound(); // Play a explosion particle GameSound.Play3D(SoundTrack.PlayerDestroy1, RobotGameGame.SinglePlayer); Matrix world = Matrix.CreateTranslation(Position); GameParticle.PlayParticle(ParticleType.DestroyHeavyMech1, world, Matrix.Identity); // vibrate the camera and the controller if (FrameworkCore.CurrentCamera.FirstCamera is FollowCamera) { ViewCamera viewCamera = FrameworkCore.CurrentCamera; FollowCamera camera = null; switch (this.PlayerIndex) { case PlayerIndex.One: camera = viewCamera.GetCamera(0) as FollowCamera; break; case PlayerIndex.Two: camera = viewCamera.GetCamera(1) as FollowCamera; break; case PlayerIndex.Three: camera = viewCamera.GetCamera(2) as FollowCamera; break; case PlayerIndex.Four: camera = viewCamera.GetCamera(3) as FollowCamera; break; } camera.SetTremble(1.0f, 0.2f); InputComponent input = FrameworkCore.InputManager.GetInputComponent(this.PlayerIndex); input.SetGamePadVibration(1.0f, 0.6f, 0.6f); } // Remove the collision if (RobotGameGame.CurrentStage is VersusStageScreen) colLayerVersusTeam[(int)this.PlayerIndex].RemoveCollide(Collide); else colLayerFriendlyMech.RemoveCollide(Collide); // Stop the booster particle and sound if (this.isActiveBooster) { if (GameSound.IsPlaying(soundBoosterPrepare)) GameSound.Stop(soundBoosterPrepare); if (GameSound.IsPlaying(soundBooster)) GameSound.Stop(soundBooster); BoosterParticleStop(); } this.SourceBlend = Blend.SourceAlpha; this.DestinationBlend = Blend.InverseSourceAlpha; this.AlphaBlendEnable = true; this.ReferenceAlpha = 0; this.isActiveBooster = false; this.isDelayBooster = false; this.actionElapsedTime = 0.0f; RobotGameGame.CurrentStage.DisableAllControlHelper(); }
/// <summary> /// attacked by enemy. takes the damage action. /// </summary> /// <param name="attacker"></param> public override void ActionDamage(GameUnit attacker) { switch (attacker.CurrentWeapon.WeaponType) { case WeaponType.PlayerHandgun: case WeaponType.PlayerMachineGun: case WeaponType.PlayerShotgun: case WeaponType.CameleerGun: case WeaponType.MaomingGun: { GameSound.Play3D(SoundTrack.HitGun, RobotGameGame.SinglePlayer); } break; case WeaponType.DuskmasCannon: case WeaponType.HammerCannon: case WeaponType.TigerCannon: { GameSound.Play3D(SoundTrack.HitCannon, RobotGameGame.SinglePlayer); } break; case WeaponType.PhantomMelee: { GameSound.Play3D(SoundTrack.HitBossMelee, RobotGameGame.SinglePlayer); } break; } if (attacker.CurrentWeapon.SpecData.CriticalDamagedFire) { if (!isActiveBooster && !IsReloading && !IsWeaponChanging) { this.prepareLowerAction = LowerAction.Damage; this.prepareUpperAction = UpperAction.Damage; this.isOverwriteLowerAction = true; this.isOverwriteUpperAction = true; if (GameSound.IsPlaying(soundRun)) GameSound.Stop(soundRun); if (GameSound.IsPlaying(soundWalk)) GameSound.Stop(soundWalk); CurrentWeapon.StopFireSound(); } // Trembling the camera if (FrameworkCore.CurrentCamera.FirstCamera is FollowCamera) { InputComponent input = FrameworkCore.InputManager.GetInputComponent(this.PlayerIndex); input.SetGamePadVibration(this.specData.CriticalDamagedTime / 2, 0.4f, 0.4f); } } }
/// <summary> /// takes an idle action. /// </summary> public override void ActionIdle() { this.prepareLowerAction = LowerAction.Idle; this.prepareUpperAction = UpperAction.Idle; CurrentWeapon.StopFireSound(); if (GameSound.IsPlaying(soundRun)) GameSound.Stop(soundRun); if (GameSound.IsPlaying(soundWalk)) GameSound.Stop(soundWalk); MoveStop(); }
/// <summary> /// acquires a sub weapon, which has been dropped on the world. /// If there is a sub weapon already, besides the default weapon, /// the current sub weapon is dropped onto the world and acquires /// the specified pickup weapon. /// </summary> /// <param name="pickupWeapon">pickup weapon</param> public void ActionPickupWeapon(GameWeapon pickupWeapon) { bool isSame = false; string message = "GOT"; // You've sub weapon if (WeaponCount > 1) { GameWeapon youveWeapon = GetWeapon(1); // You've a same sub-weapon if (youveWeapon.WeaponType == pickupWeapon.WeaponType) { youveWeapon.RemainAmmo += pickupWeapon.RemainAmmo; pickupWeapon.Discard(); isSame = true; possiblePickupWeapon = null; RobotGameGame.CurrentStage.DisableControlHelper( (int)this.PlayerIndex, 1); } // If difference, your sub weapon must be drop to world else { weaponList[1].Drop(new Vector3(Position.X, 0.5f, Position.Z), RobotGameGame.CurrentGameLevel.SceneWorldRoot, RobotGameGame.CurrentGameLevel.CollisionLayerItems); possiblePickupWeapon = weaponList[1]; weaponList.RemoveAt(1); } } else { RobotGameGame.CurrentStage.DisableControlHelper( (int)this.PlayerIndex, 1); possiblePickupWeapon = null; } // Add new weapon if (isSame == false) { weaponList.Add(pickupWeapon); pickupWeapon.Pickup(this); // Play swap action if (this.CurrentWeaponSlot != 0) { // Swap the new weapon SelectWeapon(1); // Update selected weapon image in the Hud RobotGameGame.CurrentStage.SetCurrentWeaponHud( (int)this.PlayerIndex, CurrentWeapon.WeaponType); this.prepareUpperAction = UpperAction.WeaponChange; if (CurrentWeapon.NeedToReload) { RobotGameGame.CurrentStage.DisplayControlHelper( (int)this.PlayerIndex, 0, "(RB) RELOAD"); } else { RobotGameGame.CurrentStage.DisableControlHelper( (int)this.PlayerIndex, 0); } } } // Play the pick up sound GameSound.Play3D(SoundTrack.PickupWeapon, RobotGameGame.SinglePlayer); switch(pickupWeapon.WeaponType) { case WeaponType.PlayerShotgun: { message += " SHOTGUN"; } break; case WeaponType.PlayerHandgun: { message += " HANDGUN"; } break; } // Display the pick up message to screen RobotGameGame.CurrentStage.DisplayPickup((int)this.PlayerIndex, message, 3.0f); }
/// <summary> /// changes to the sub weapon. /// </summary> public void ActionSwapSubWeapon() { if (IsPossibleWeaponChange) { CurrentWeapon.StopFireSound(); // Swap the sub weapon ChangeWeapon(1); // Play the sound GameSound.Play3D(SoundTrack.PlayerSwapWeapon, RobotGameGame.SinglePlayer); this.prepareUpperAction = UpperAction.WeaponChange; if (CurrentWeapon.NeedToReload) { RobotGameGame.CurrentStage.DisplayControlHelper( (int)this.PlayerIndex, 0, "(RB) RELOAD"); } else { RobotGameGame.CurrentStage.DisableControlHelper( (int)this.PlayerIndex, 0); } } }
/// <summary> /// an animation of booster getting interrupted. /// </summary> protected void ActionBoosterBreak() { this.isActiveBooster = true; this.isDelayBooster = true; this.actionElapsedTime = 0.0f; this.boosterWaveEffectTime = 0.0f; this.prepareLowerAction = LowerAction.BoosterBreak; this.prepareUpperAction = UpperAction.BoosterBreak; if (GameSound.IsPlaying(soundBoosterPrepare)) GameSound.Stop(soundBoosterPrepare); if (GameSound.IsPlaying(soundBooster)) GameSound.Stop(soundBooster); // Stop the particle BoosterParticleStop(); // Vibrate a camera and controller if (FrameworkCore.CurrentCamera.FirstCamera is FollowCamera) { ViewCamera viewCamera = FrameworkCore.CurrentCamera; FollowCamera camera = null; switch (this.PlayerIndex) { case PlayerIndex.One: camera = viewCamera.GetCamera(0) as FollowCamera; break; case PlayerIndex.Two: camera = viewCamera.GetCamera(1) as FollowCamera; break; case PlayerIndex.Three: camera = viewCamera.GetCamera(2) as FollowCamera; break; case PlayerIndex.Four: camera = viewCamera.GetCamera(3) as FollowCamera; break; } camera.SetTremble(0.6f, 0.1f); InputComponent input = FrameworkCore.InputManager.GetInputComponent(this.PlayerIndex); input.SetGamePadVibration(boosterBreakDurationTime / 2, 0.3f, 0.3f); } }
public override void FixedUpdate() { if (!controller.grounded) { //不在地面 inAirTime += Time.fixedDeltaTime; if (inAirTime > 0.2f) { controller.IntoState(PlayerStateType.InAir); } } else { //在地面 inAirTime = 0; if (controller.input.jump) { if (controller.EnergyCost(Player.jumpEnergyCost) > 0) { controller.IntoState(PlayerStateType.Jump); } } else if (controller.input.roll) { if (controller.EnergyCost(Player.rollEnergyCost) > 0) { controller.IntoState(PlayerStateType.Roll); } } else if (controller.input.mainHand) { if (player.weaponType == WeaponType.Melee) { if (controller.EnergyCost(Player.attackEnergyCost) > 0) { if (controller.comboCount == 1) { controller.IntoState(PlayerStateType.Attack, "Attack1"); controller.comboCount = 0; } else if (controller.comboCount == 0) { TimeSpan span = DateTime.Now - controller.lastAttackDoneTime; if (span.TotalMilliseconds < 300) { controller.IntoState(PlayerStateType.Attack, "Attack2"); controller.comboCount = 1; } else { controller.IntoState(PlayerStateType.Attack, "Attack1"); } } } } } else if (controller.input.offHand && player.weaponType == WeaponType.Pistol) { controller.IntoState(PlayerStateType.Aim); } else { if (controller.input.swapWeapon) //切换武器 { if (upperAction != UpperAction.SwapWeapon) { if (player.weaponType == WeaponType.Melee) { nextWeapon = WeaponType.Pistol; } else { nextWeapon = WeaponType.Melee; } player.SetUpperAniState(Player.StateNameHash.swapWeapon); upperAction = UpperAction.SwapWeapon; } } if (controller.input.offHand && player.weaponType == WeaponType.Melee && upperAction == UpperAction.Empty) //格挡 { player.blocking = true; } else { player.blocking = false; } if (!controller.input.hasMove) //没输入方向,idle { if (player.targetId > 0) { Player target = UnityHelper.GetLevelManager().GetPlayer(player.targetId); controller.faceYaw = CommonHelper.YawOfVector3(target.transform.position - player.transform.position); } if (player.blocking) { if (upperAction == UpperAction.Empty) { player.SetLowerAniState(Player.StateNameHash.blockIdle); } player.SetUpperAniState(Player.StateNameHash.blockIdle); } else { if (upperAction == UpperAction.Empty) { player.SetUpperAniState(Player.StateNameHash.idle); } player.SetLowerAniState(Player.StateNameHash.idle); } controller.rigidBody.Sleep(); controller.moveSpeed = Player.walkSpeed; //idle时,重置移动速度 player.footIk = true; } else //输入了方向,则移动 { player.footIk = false; if (player.targetId >= 0 && !controller.input.run) { StrafeMove(); } else { NormalMove(); //普通移动 } } } } }
/// <summary> /// takes the shooting action. /// </summary> public override bool ActionFire() { UpperAction forwardFire = UpperAction.Count; UpperAction leftFire = UpperAction.Count; UpperAction rightFire = UpperAction.Count; // Firing animation switch (this.CurrentWeapon.WeaponType) { case WeaponType.PlayerMachineGun: { forwardFire = UpperAction.ForwardMachineGunFire; leftFire = UpperAction.LeftMachineGunFire; rightFire = UpperAction.RightMachineGunFire; } break; case WeaponType.PlayerShotgun: { forwardFire = UpperAction.ForwardShotgunFire; leftFire = UpperAction.LeftShotgunFire; rightFire = UpperAction.RightShotgunFire; } break; case WeaponType.PlayerHandgun: { forwardFire = UpperAction.ForwardHandgunFire; leftFire = UpperAction.LeftHandgunFire; rightFire = UpperAction.RightHandgunFire; } break; } // active booster ? if (isActiveBooster) { this.prepareUpperAction = forwardFire; this.isOverwriteUpperAction = true; // Retry playing action } else { // Left moving fire if (this.moveDirection.X < 0.0f) { // Forward left moving fire if (this.moveDirection.Z > 0.0f) { this.prepareUpperAction = leftFire; } // Backward left moving fire else if (this.moveDirection.Z < 0.0f) { this.prepareUpperAction = rightFire; } // Left moving fire else { this.prepareUpperAction = leftFire; } this.isOverwriteUpperAction = true; // Retry playing action } // Right moving Fire else if (this.moveDirection.X > 0.0f) { // Forward right moving fire if (this.moveDirection.Z > 0.0f) { this.prepareUpperAction = rightFire; } // Backward right moving fire else if (this.moveDirection.Z < 0.0f) { this.prepareUpperAction = leftFire; } // Right moving fire else { this.prepareUpperAction = rightFire; } this.isOverwriteUpperAction = true; // Retry playing action } // Forward or Backward moving Fire else { this.prepareUpperAction = forwardFire; this.isOverwriteUpperAction = true; // Retry playing action } } return false; }