pinball/assets/_Game/Scripts/Environments/GoalAnimaton.ts

43 lines
1.4 KiB
TypeScript
Raw Normal View History

2024-06-12 04:48:19 -07:00
import { _decorator, Component, Node } from 'cc';
import SpineAnimationHandler from '../Base/SpineAnimationHandler';
import ScoreType from '../Enum/ScoreType';
import GameEvent from '../Events/GameEvent';
import { EventManger } from '../Manager/EventManger';
const { ccclass, property } = _decorator;
@ccclass('GoalAnimation')
export default class GoalAnimation extends Component {
@property(SpineAnimationHandler)
private animationHandler: SpineAnimationHandler;
private index: number = 1;
protected onEnable(): void {
this.animationHandler.setAnimation('stage' + this.index, { loop: true });
EventManger.instance.on(GameEvent.Score, this.onScore, this);
EventManger.instance.on(GameEvent.BallOut, this.onBallOut, this);
}
protected onDisable(): void {
EventManger.instance.off(GameEvent.Score, this.onScore, this);
EventManger.instance.off(GameEvent.BallOut, this.onBallOut, this);
}
private onScore(score: number, points: number, type: ScoreType) {
if (type == ScoreType.Goal) {
if (this.index < 5) {
this.index++;
this.animationHandler.setAnimation('stage' + this.index, { loop: true });
}
}
}
private onBallOut() {
if (this.index > 1) {
this.index--;
this.animationHandler.setAnimation('stage' + this.index, { loop: true });
}
}
}