import { _decorator, CCFloat, Collider2D, Component, Contact2DType, Animation, AudioClip } 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'; import { SoundManager } from '../Manager/SoundManager'; const { ccclass, property } = _decorator; @ccclass('BoosterBase') export class BoosterBase extends Component implements IPoolable { @property({ type: Collider2D, visible: true }) protected _collider: Collider2D; @property({ type: AudioClip, visible: true }) protected _collectSound: AudioClip; @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); this._collider.enabled = false; } private onContactBegin(self: Collider2D, other: Collider2D) { this.boosterActive(); this._collider.enabled = false; SoundManager.instance.playSfx(this._collectSound); 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() { this._collider.enabled = false; } }