From 609b952823b1a1ed7f855fca1116280f9808cc44 Mon Sep 17 00:00:00 2001 From: yangwen Date: Thu, 5 Jun 2025 15:16:43 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B4=E7=90=86=E4=BB=A3=E7=A0=81=E6=A0=BC?= =?UTF-8?q?=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/models/ResourceManager.ts | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/src/models/ResourceManager.ts b/src/models/ResourceManager.ts index 5ca66d2..4a701b2 100644 --- a/src/models/ResourceManager.ts +++ b/src/models/ResourceManager.ts @@ -1,7 +1,5 @@ import { respath } from "../constants/respath" - - export class ResourceManager { private static instance: ResourceManager public static getInstance(): ResourceManager { @@ -14,9 +12,7 @@ export class ResourceManager { private resources: Array<{ url: string, type?: any, lazy?: boolean }> = [] private reqs: Map> = new Map() - public init(): void { - this.resources.push({ url: respath.score_add_ui_res() }) this.resources.push({ url: respath.dc_ui_res() }) this.resources.push({ url: respath.trophy_ui_res() }) @@ -43,19 +39,18 @@ export class ResourceManager { Laya.loader.load(this.resources, Laya.Handler.create(this, (obj: object) => { // 第二个参数:成功回调 console.log("预加载资源结束>>>>", obj) - this.reqs.forEach((list: Array, path: string)=>{ - for (let i = 0; i < list.length; i++) { - const img = list[i] - if (img && img.parent) { - img.texture = Laya.loader.getRes(path) - } + this.reqs.forEach((list: Array, path: string) => { + for (let i = 0; i < list.length; i++) { + const img = list[i] + if (img && img.parent) { + img.texture = Laya.loader.getRes(path) } + } }) this.reqs.clear() }), Laya.Handler.create(this, (resProg: number) => { // 第三个参数:进度回调 - // console.log("预加载资源进度>>>>", resProg) + console.log("预加载资源进度>>>>", resProg) })) - } public loadTexture(path: string, image: Laya.Image): void { @@ -66,9 +61,9 @@ export class ResourceManager { image.texture = obj } else { if (!this.reqs.has(path)) { - this.reqs.set(path, new Array()) + this.reqs.set(path, []) } - let list = this.reqs.get(path) + const list = this.reqs.get(path) list.push(image) let find = false @@ -91,11 +86,8 @@ export class ResourceManager { } } this.reqs.delete(path) - }), Laya.Handler.create(this, (resProg: number) => { // 第三个参数:进度回调 - // console.log("加载资源进度>>>>", path, resProg) })) } - } } }