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 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: 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 _enabled: boolean = true; protected onLoad(): void { this._collider.on(Contact2DType.BEGIN_CONTACT, this.onContactBegin, this); this._enabled = false; } private onContactBegin(self: Collider2D, other: Collider2D) { if (!this._enabled) return; this.boosterActive(); this._enabled = 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 Utilities.delay(this._animation.defaultClip.duration); this._enabled = true; } onRelease() { this._enabled = false; } }