UI_Loading.ts 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import { GameUILayers } from "../../scripts/GameUILayers";
  2. import { UI_LoadingExtra } from "../../scripts/UIDef";
  3. import { Layout_Loading } from "./Layout_Loading";
  4. import { assetManager, Prefab } from "cc";
  5. export class UI_Loading extends UI_LoadingExtra {
  6. constructor() {
  7. super('ui_loading/UI_Loading', GameUILayers.CBL,Layout_Loading);
  8. }
  9. protected onCreated(): void {
  10. let layout = this.layout as Layout_Loading;
  11. layout.loadingBar.init()
  12. }
  13. private _res_confs:{bundle:string,url:string[]}=null;
  14. private _on_complete:()=>void;
  15. private _target:any;
  16. public Init(res_confs:{bundle:string,url:string[]},on_complete?:()=>void,target?:any):void{
  17. this._on_complete=on_complete;
  18. this._target=target;
  19. this._res_confs=res_confs;
  20. this.preloadRes();
  21. }
  22. //
  23. private preloadRes() {
  24. let res = this._res_confs;
  25. let bundle = assetManager.getBundle(res.bundle);
  26. let layout = this.layout as Layout_Loading;
  27. if (!bundle){
  28. this.complete();
  29. }else{
  30. bundle.load<Prefab>(res.url,(finished: number, total: number, item:any) => {
  31. layout.loadingBar.set(finished/total);
  32. }, (err: Error | null, data) => {
  33. this.complete();
  34. });
  35. }
  36. }
  37. //
  38. private complete():void{
  39. this._on_complete?.call(this._target);
  40. this._on_complete=null;
  41. this._target=null;
  42. this._res_confs=null;
  43. this.close();
  44. }
  45. //
  46. protected onDispose() :void{
  47. }
  48. //
  49. }