import { respath } from "../constants/respath" import { StorageManager } from "./StorageManager" import { Stage } from "../views/Stage" const { regClass, property } = Laya @regClass() export class UIManager extends Laya.Script { declare owner: Laya.Scene private static _instance: UIManager onAwake(): void { UIManager._instance = this StorageManager.getInstance().init() this.loadHome() } public static getInstance(): UIManager { return UIManager._instance } private stage: Stage public loadHome(): void { Laya.loader.load(respath.home_ui_res).then((go)=>{ var prefab = go.create() this.owner.addChild(prefab) }) } public loadStage(stageID: string, clean: boolean=false): void { if (clean) { StorageManager.getInstance().cleanStage() } if (this.stage) { this.stage.onLoadStage(StorageManager.getInstance().loadStage(stageID)) } else { Laya.loader.load(respath.stage_ui_res).then((go)=>{ var prefab = go.create() this.stage = this.owner.addChild(prefab).getComponent(Stage) this.stage.onLoadStage(StorageManager.getInstance().loadStage(stageID)) }) } } public closeStage(): void { if (this.stage) { this.stage.owner.destroy() this.stage = null } } public loadGameOver(): void { Laya.loader.load(respath.gameover_ui_res).then((go)=>{ var prefab = go.create() this.owner.addChild(prefab) }) } public loadGameDone(): void { Laya.loader.load(respath.gamedone_ui_res).then((go)=>{ var prefab = go.create() this.owner.addChild(prefab) }) } onLateUpdate(): void { StorageManager.getInstance().saveStage() } }