调整预加载资源时机
This commit is contained in:
@@ -15,6 +15,28 @@ export class ResourceManager {
|
||||
private prefabReqs: Map<string, Array<any>> = new Map()
|
||||
|
||||
public init(): void {
|
||||
Laya.timer.frameLoop(1, this, () => {
|
||||
const removes: Array<any> = []
|
||||
this.prefabReqs.forEach((list: Array<any>, path: string) => {
|
||||
const obj = Laya.loader.getRes(path)
|
||||
if (obj) {
|
||||
removes.push(path)
|
||||
for (let i = 0; i < list.length; i++) {
|
||||
list[i](obj)
|
||||
}
|
||||
}
|
||||
})
|
||||
for (let i = 0; i < removes.length; i++) {
|
||||
this.prefabReqs.delete(removes[i])
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
private started : boolean = false
|
||||
public startSchedule(): void {
|
||||
if (this.started)
|
||||
return
|
||||
this.started = true
|
||||
this.resources.push({ url: respath.gamepause_ui_res() })
|
||||
this.resources.push({ url: respath.gameover_ui_res() })
|
||||
this.resources.push({ url: respath.gamedone_ui_res(true) })
|
||||
@@ -75,22 +97,6 @@ export class ResourceManager {
|
||||
}), Laya.Handler.create(this, (resProg: number) => { // 第三个参数:进度回调
|
||||
console.log("预加载资源进度>>>>", resProg)
|
||||
}))
|
||||
|
||||
Laya.timer.frameLoop(1, this, () => {
|
||||
const removes: Array<any> = []
|
||||
this.prefabReqs.forEach((list: Array<any>, path: string) => {
|
||||
const obj = Laya.loader.getRes(path)
|
||||
if (obj) {
|
||||
removes.push(path)
|
||||
for (let i = 0; i < list.length; i++) {
|
||||
list[i](obj)
|
||||
}
|
||||
}
|
||||
})
|
||||
for (let i = 0; i < removes.length; i++) {
|
||||
this.prefabReqs.delete(removes[i])
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
public loadTexture(path: string, image: Laya.Image): void {
|
||||
@@ -133,7 +139,7 @@ export class ResourceManager {
|
||||
|
||||
public loadPrefab(path: string, callback: any): void {
|
||||
const obj = Laya.loader.getRes(path)
|
||||
// console.log("loadPrefab >>>>>", path, obj)
|
||||
console.log("loadPrefab >>>>>", path, obj)
|
||||
if (obj) {
|
||||
if (callback) {
|
||||
callback(obj)
|
||||
|
||||
@@ -84,6 +84,7 @@ export class UIManager extends Laya.Script {
|
||||
ResourceManager.getInstance().loadPrefab(respath.home_ui_res, (go: any) => {
|
||||
const prefab = go.create()
|
||||
this.getUIRoot().addChild(prefab)
|
||||
ResourceManager.getInstance().startSchedule()
|
||||
})
|
||||
}
|
||||
|
||||
@@ -177,6 +178,7 @@ export class UIManager extends Laya.Script {
|
||||
const prefab = go.create()
|
||||
this.stage = this.getUIRoot().addChild(prefab).getComponent(Stage)
|
||||
this.stage.onLoadStage(StorageManager.getInstance().loadStage(stageID))
|
||||
ResourceManager.getInstance().startSchedule()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user