SingleShotWeapon.ts 1.7 KB

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