From 8ce3edb6a9d64b8679aa182d08cd6a1317b69736 Mon Sep 17 00:00:00 2001 From: Martin Date: Mon, 30 Jan 2023 14:25:43 +0100 Subject: [PATCH] Close at various times, depending on the animation --- .../Services/ModalWindowSystem/ModalWindow.ts | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/assets/Scripts/Services/ModalWindowSystem/ModalWindow.ts b/assets/Scripts/Services/ModalWindowSystem/ModalWindow.ts index fa5471b..8c49ca2 100644 --- a/assets/Scripts/Services/ModalWindowSystem/ModalWindow.ts +++ b/assets/Scripts/Services/ModalWindowSystem/ModalWindow.ts @@ -12,16 +12,19 @@ export abstract class ModalWindow extends Component { private result: TResult; private isDismissed = false; + private openAnimationName = "open"; + private closeAnimationName = "close"; + public async runAsync(params?: TParam): Promise { this.closeButton?.InteractedEvent.on(() => this.dismiss(), this); this.backgroundCloseButton?.InteractedEvent.on(() => this.dismiss(), this); this.setup(params); - this.animation?.play("open"); + this.animation?.play(this.openAnimationName); while (!this.isDismissed) await delay(100); - this.animation?.play("close"); + this.animation?.play(this.closeAnimationName); - await delay(500); + await delay(this.getCloseAnimationTime() * 1000); return this.result; } @@ -31,4 +34,13 @@ export abstract class ModalWindow extends Component { this.result = result; this.isDismissed = true; } + + private getCloseAnimationTime(): number { + const state = this.animation?.getState(this.closeAnimationName); + if (state != null) { + return state.duration; + } + + return 0; + } }