2022-12-31 11:29:27 +00:00
|
|
|
import { Animation, Component, _decorator } from "cc";
|
|
|
|
import { delay } from "../Services/Utils/AsyncUtils";
|
|
|
|
const { ccclass, property } = _decorator;
|
|
|
|
|
|
|
|
@ccclass("OpenCloseAnimator")
|
|
|
|
export class OpenCloseAnimator extends Component {
|
|
|
|
@property(Animation) private animation: Animation;
|
|
|
|
|
|
|
|
private readonly openStateName = "Open";
|
|
|
|
private readonly closeStateName = "Close";
|
|
|
|
|
|
|
|
private openDuration = 0;
|
|
|
|
private closeDuration = 0;
|
|
|
|
|
2022-12-31 12:32:40 +00:00
|
|
|
public init(): void {
|
2022-12-31 11:29:27 +00:00
|
|
|
this.openDuration = this.animation.getState(this.openStateName).duration;
|
|
|
|
this.closeDuration = this.animation.getState(this.closeStateName).duration;
|
|
|
|
}
|
|
|
|
|
|
|
|
public async playOpen(): Promise<void> {
|
|
|
|
this.node.active = true;
|
|
|
|
this.animation.play(this.openStateName);
|
2022-12-31 12:32:40 +00:00
|
|
|
await delay(this.openDuration * 1000);
|
2022-12-31 11:29:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public async playClose(): Promise<void> {
|
|
|
|
this.node.active = true;
|
2022-12-31 12:32:40 +00:00
|
|
|
this.animation.play(this.closeStateName);
|
|
|
|
await delay(this.closeDuration * 1000);
|
2022-12-31 11:29:27 +00:00
|
|
|
this.node.active = false;
|
|
|
|
}
|
|
|
|
}
|