import { _decorator, CCFloat, Collider2D, Component, Contact2DType, Animation } from 'cc'; import ObjectPool from '../Pool/ObjectPool'; import { EventManger } from '../Manager/EventManger'; import GameEvent from '../Events/GameEvent'; import IPoolable from '../Pool/IPoolable'; import Utilities from '../Utilities'; const { ccclass, property } = _decorator; @ccclass('BoosterBase') export class BoosterBase extends Component implements IPoolable { @property({ type: Collider2D, visible: true }) protected _collider: Collider2D; @property({ type: Animation, visible: true }) private _animation: Animation; @property(CCFloat) protected time: number = 10; protected onLoad(): void { this._collider.on(Contact2DType.BEGIN_CONTACT, this.onContactBegin, this); } private onContactBegin(self: Collider2D, other: Collider2D) { this.boosterActive(); EventManger.instance.emit(GameEvent.ObjectRelease, this.node); ObjectPool.release(this.node); } protected boosterActive?(): void; async onGet() { this._animation.play(); await Utilities.delay(this._animation.defaultClip.duration); this._collider.enabled = true; } onRelease() {} }