整理代码格式

This commit is contained in:
2025-06-05 15:16:43 +08:00
parent c2726c790a
commit 609b952823

View File

@@ -1,7 +1,5 @@
import { respath } from "../constants/respath" import { respath } from "../constants/respath"
export class ResourceManager { export class ResourceManager {
private static instance: ResourceManager private static instance: ResourceManager
public static getInstance(): ResourceManager { public static getInstance(): ResourceManager {
@@ -14,9 +12,7 @@ export class ResourceManager {
private resources: Array<{ url: string, type?: any, lazy?: boolean }> = [] private resources: Array<{ url: string, type?: any, lazy?: boolean }> = []
private reqs: Map<string, Array<Laya.Image>> = new Map() private reqs: Map<string, Array<Laya.Image>> = new Map()
public init(): void { public init(): void {
this.resources.push({ url: respath.score_add_ui_res() }) this.resources.push({ url: respath.score_add_ui_res() })
this.resources.push({ url: respath.dc_ui_res() }) this.resources.push({ url: respath.dc_ui_res() })
this.resources.push({ url: respath.trophy_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) => { // 第二个参数:成功回调 Laya.loader.load(this.resources, Laya.Handler.create(this, (obj: object) => { // 第二个参数:成功回调
console.log("预加载资源结束>>>>", obj) console.log("预加载资源结束>>>>", obj)
this.reqs.forEach((list: Array<Laya.Image>, path: string)=>{ this.reqs.forEach((list: Array<Laya.Image>, path: string) => {
for (let i = 0; i < list.length; i++) { for (let i = 0; i < list.length; i++) {
const img = list[i] const img = list[i]
if (img && img.parent) { if (img && img.parent) {
img.texture = Laya.loader.getRes(path) img.texture = Laya.loader.getRes(path)
}
} }
}
}) })
this.reqs.clear() this.reqs.clear()
}), Laya.Handler.create(this, (resProg: number) => { // 第三个参数:进度回调 }), Laya.Handler.create(this, (resProg: number) => { // 第三个参数:进度回调
// console.log("预加载资源进度>>>>", resProg) console.log("预加载资源进度>>>>", resProg)
})) }))
} }
public loadTexture(path: string, image: Laya.Image): void { public loadTexture(path: string, image: Laya.Image): void {
@@ -66,9 +61,9 @@ export class ResourceManager {
image.texture = obj image.texture = obj
} else { } else {
if (!this.reqs.has(path)) { 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) list.push(image)
let find = false let find = false
@@ -91,11 +86,8 @@ export class ResourceManager {
} }
} }
this.reqs.delete(path) this.reqs.delete(path)
}), Laya.Handler.create(this, (resProg: number) => { // 第三个参数:进度回调
// console.log("加载资源进度>>>>", path, resProg)
})) }))
} }
} }
} }
} }