import { Component, instantiate, Node, Prefab, _decorator } from "cc"; import { ModalWindow } from "./ModalWindow"; const { ccclass, property } = _decorator; @ccclass("ModalWindowManager") export class ModalWindowManager extends Component { @property(Prefab) private availableWindows: Prefab[] = []; public async showModal(name: string, params: TParams): Promise { const windowPrefab: Prefab = this.availableWindows.find((w) => w.name === name); const windowNode: Node = instantiate(windowPrefab); windowNode.setParent(this.node); const modalWindow: ModalWindow = >windowNode.getComponent(name); const result: TResult = await modalWindow.runAsync(params); windowNode.destroy(); return result; } }