import { GameUILayers } from "../../scripts/GameUILayers"; import { UI_LoadingExtra } from "../../scripts/UIDef"; import { Layout_Loading } from "./Layout_Loading"; import { assetManager, Prefab } from "cc"; export class UI_Loading extends UI_LoadingExtra { constructor() { super('ui_loading/UI_Loading', GameUILayers.CBL,Layout_Loading); } protected onCreated(): void { let layout = this.layout as Layout_Loading; layout.loadingBar.init() } private _res_confs:{bundle:string,url:string[]}=null; private _on_complete:()=>void; private _target:any; public Init(res_confs:{bundle:string,url:string[]},on_complete?:()=>void,target?:any):void{ this._on_complete=on_complete; this._target=target; this._res_confs=res_confs; this.preloadRes(); } // private preloadRes() { let res = this._res_confs; let bundle = assetManager.getBundle(res.bundle); let layout = this.layout as Layout_Loading; if (!bundle){ this.complete(); }else{ bundle.load(res.url,(finished: number, total: number, item:any) => { layout.loadingBar.set(finished/total); }, (err: Error | null, data) => { this.complete(); }); } } // private complete():void{ this._on_complete?.call(this._target); this._on_complete=null; this._target=null; this._res_confs=null; this.close(); } // protected onDispose() :void{ } // }