AniFinishDestroy.ts 1022 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import PoolMgr, { NODEPOOLPREFABTYPE } from "../../mgr/PoolMgr";
  2. const { ccclass, property } = cc._decorator;
  3. @ccclass
  4. export default class AniFinishDestroy extends cc.Component {
  5. private ani: cc.Animation = null;
  6. private callBack: Function = null;
  7. // LIFE-CYCLE CALLBACKS:
  8. onLoad() {
  9. this.ani = this.node.getComponent(cc.Animation);
  10. this.ani.on('finished', this.onAniPlayFinished, this);
  11. }
  12. start() {
  13. }
  14. // update (dt) {}
  15. init(callBack: Function = null) {
  16. if (!this.ani) {
  17. this.ani = this.node.getComponent(cc.Animation);
  18. this.ani.on('finished', this.onAniPlayFinished, this);
  19. }
  20. this.callBack = callBack;
  21. this.ani.play();
  22. }
  23. onAniPlayFinished() {
  24. if (this.callBack) {
  25. this.callBack();
  26. }
  27. this.recycle();
  28. }
  29. recycle() {
  30. PoolMgr.Inst.recyclePoolPrefab(NODEPOOLPREFABTYPE[this.node.name], this.node);
  31. }
  32. }