GunBase.ts 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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).forEach(e => {
  40. e.stop();
  41. e.play();
  42. });
  43. }
  44. }