GunBase.ts 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import { _decorator, Component, SpriteFrame,Node, ParticleSystem } from 'cc';
  2. import { eventEmitter } from '../../core/event/EventEmitter';
  3. import { Constants } from '../../data/Constants';
  4. const { ccclass, property } = _decorator;
  5. @ccclass('GunBase')
  6. export class GunBase extends Component {
  7. @property({type: Node,tooltip:"枪口节点"})
  8. public muzzleNode: Node = null!
  9. public data: any = null;//枪的数据
  10. public isFire: boolean = false;//是否在开火状态
  11. public endCb: Function = null;//结束回调
  12. public bulletSF: SpriteFrame = null!;//子弹贴图 需要的替换贴图的设置
  13. //射击出去的子弹数
  14. private _shotBullets: number = 0;
  15. public set shotBullets(value: number) {
  16. this._shotBullets = value;
  17. eventEmitter.dispatch(Constants.eventName.magazine_num_change);
  18. }
  19. public get shotBullets() {
  20. return this._shotBullets;
  21. }
  22. constructor(){
  23. super();
  24. this.isFire = false;
  25. this.endCb = null;
  26. }
  27. init(data: any,holder: any,endCb?: Function,ammoCb?: Function){
  28. }
  29. /**开火*/
  30. fire(){
  31. }
  32. endFire(){
  33. }
  34. /**
  35. * 播放粒子特效
  36. * @param node 粒子节点
  37. */
  38. public playParticle(node:Node){
  39. node.getComponentsInChildren(ParticleSystem)
  40. .forEach(e => {
  41. e.stop();
  42. e.play();
  43. });
  44. }
  45. }