pinball/assets/_Game/Scripts/Booster/CumulativeBooster.ts

46 lines
1.4 KiB
TypeScript
Raw Normal View History

2024-03-27 04:00:23 -07:00
import { _decorator, Component, Node } from 'cc';
2024-06-12 04:48:19 -07:00
import SpineAnimationHandler from '../Base/SpineAnimationHandler';
2024-03-27 04:00:23 -07:00
import BoosterType from '../Enum/BoosterType';
2024-06-10 23:38:06 -07:00
import AudioManager from '../Manager/AudioManager';
import { BoosterBase } from './BoosterBase';
2024-03-27 04:00:23 -07:00
const { ccclass, property } = _decorator;
@ccclass('CumulativeBooster')
export class CumulativeBooster extends BoosterBase {
2024-06-12 04:48:19 -07:00
@property(SpineAnimationHandler)
private animationHandler: SpineAnimationHandler;
2024-06-10 23:38:06 -07:00
public readonly type: BoosterType = BoosterType.CumulativeBar;
2024-06-12 04:48:19 -07:00
protected onLoad(): void {
super.onLoad();
this.animationHandler?.setNodeActive(false);
}
public async collect(collector: Node): Promise<void> {
2024-06-10 23:38:06 -07:00
super.collect(collector);
AudioManager.setPlayRateBGM(1.5);
await this.animationHandler?.setAnimationAsync('active');
this.animationHandler?.setNodeActive(false);
2024-06-10 23:38:06 -07:00
}
public end(): void {
super.end();
AudioManager.setPlayRateBGM(1);
2024-03-27 04:00:23 -07:00
}
2024-06-12 04:48:19 -07:00
async onGet(): Promise<void> {
await super.onGet();
if (this.animationHandler) {
this.animationHandler.setNodeActive(true);
this.animationHandler.setAnimation('idle', { loop: true });
2024-06-12 04:48:19 -07:00
this.sprite.setNodeActive(false);
}
}
onRelease(): void {
super.onRelease();
this.animationHandler?.setNodeActive(false);
}
2024-03-27 04:00:23 -07:00
}