SingleShotWeapon.ts 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import { _decorator, Component, Node, AnimationComponent } from 'cc';
  2. import { GameController } from '../GameController';
  3. import { WeaponBase } from './WeaponBase';
  4. const { ccclass, property } = _decorator;
  5. export class SingleShotWeapon extends WeaponBase {
  6. constructor(leftHand:AnimationComponent,rightHand:AnimationComponent){
  7. super(leftHand,rightHand);
  8. }
  9. Fire(bullet:boolean):void{
  10. super.Fire(bullet);
  11. if(this.fireKey==1){
  12. this.FireLeft();
  13. }else if(this.fireKey==3){
  14. this.FireRight();
  15. }else{
  16. this.isLeftFire=!this.isLeftFire;
  17. if(this.isLeftFire){
  18. this.FireLeft();
  19. }else{
  20. this.FireRight();
  21. }
  22. }
  23. if(bullet){
  24. this.bulletCount--;
  25. }
  26. }
  27. private FireLeft():void{
  28. GameController.single.WeaponAttack();
  29. this.isLeftFire=true;
  30. this.leftHand.on(AnimationComponent.EventType.FINISHED,this.FireCompleteHandler,this,true);
  31. this.leftHand.play(this.weaponConfig.handFireAnimation);
  32. this.rightHand.crossFade("Idle",0.5);
  33. this.leftGunFire.play(this.weaponConfig.gunFireAnimation);
  34. }
  35. private FireRight():void{
  36. GameController.single.WeaponAttack();
  37. this.isLeftFire=false;
  38. this.rightHand.on(AnimationComponent.EventType.FINISHED,this.FireCompleteHandler,this,true);
  39. this.rightHand.play(this.weaponConfig.handFireAnimation);
  40. this.leftHand.crossFade("Idle",0.5);
  41. this.rightGunFire.play(this.weaponConfig.gunFireAnimation);
  42. }
  43. private FireCompleteHandler():void{
  44. this.isFire=false;
  45. if(this.isLeftFire){
  46. this.leftHand.crossFade("Idle",0.5);
  47. }else{
  48. this.rightHand.crossFade("Idle",0.5)
  49. }
  50. }
  51. }