大侠
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

70 lines
2.0 KiB

import { Global } from "../Global";
import ResLoad from "../ResUrl/ResLoad";
import { LoadingMgr } from "./LoadingMgr";
export class AllLoadingMgr{
private onProgress: (progress: number, message: string, detailMessage?: string) => void;
private onComplete: () => void;
private onError: (error: any) => void;
private _list: LoadingMgr[] = [];
private _Completes:boolean[] =[];
/**默认显示最后一个加载队列进度 */
private _show: number = -1;
constructor(
onProgress: (progress: number, message: string, detailMessage?: string) => void,
onComplete: () => void,
onError: (error: any) => void
) {
this.onProgress = onProgress;
this.onComplete = onComplete;
this.onError = onError;
}
addLoadingMgr(task:LoadingMgr){
let tIndex:number = this._list.length;
task.initCallBack(
(progress: number, message: string) => {
this.Progress(tIndex,progress,message);
},
() => {
this._Completes[tIndex] = true;
this.Complete();
},
(error: any) => {
console.error("初始化失败:", error);
this.Error(error);
})
this._list.push(task);
this._Completes.push(false);
}
start(){
if (this._show < 0) { this._show = this._list.length - 1 }
for (let i = 0; i < this._list.length; i++) {
this._list[i].start();
}
}
private Progress(tIndex:number,progress: number, message: string){
if(this._show == tIndex){
this.onProgress(progress, message);
}
}
private Error(...value){
this.onError(value);
}
private Complete(){
for (let i = 0; i < this._Completes.length; i++) {
if(!this._Completes[i]){return false};
}
/**初始化震动 */
Global.Vibrate.init();
/**音频管理器 */
Global.Audio.init();
this.onComplete();
}
}