import { _decorator, Animation, AudioClip, CCFloat, CCString, Collider2D, Component, Contact2DType } from 'cc'; import GameEvent from '../Events/GameEvent'; import AudioManager from '../Manager/AudioManager'; import { EventManger } from '../Manager/EventManger'; import IPoolable from '../Pool/IPoolable'; import ObjectPool from '../Pool/ObjectPool'; import Utils 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: AudioClip, visible: true }) protected _collectSound: AudioClip; @property({ type: Animation, visible: true }) private _animation: Animation; @property(CCString) public readonly displayName: string = 'CHEESE'; @property(CCFloat) protected time: number = 10; private active: boolean = true; protected onLoad(): void { this._collider.on(Contact2DType.BEGIN_CONTACT, this.onContactBegin, this); this.active = false; } private onContactBegin(self: Collider2D, other: Collider2D) { if (!this.active) return; this.boosterActive(); this.active = false; AudioManager.playSfx(this._collectSound); EventManger.instance.emit(GameEvent.ObjectRelease, this.node); ObjectPool.release(this.node); } protected boosterActive?(): void; async onGet() { this._animation.play(); await Utils.delay(this._animation.defaultClip.duration); this.active = true; } onRelease() { this.active = false; } }