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.
124 lines
3.1 KiB
124 lines
3.1 KiB
import ResLoad from "../ResUrl/ResLoad";
|
|
import ResLoadGroup from "../ResUrl/ResLoadGroup";
|
|
import ResLoadItem from "../ResUrl/ResLoadItem";
|
|
|
|
|
|
/**
|
|
* 包配置接口
|
|
*/
|
|
export interface ISubpackages {
|
|
/** 关键资源名字 */
|
|
name: string,
|
|
/** 路径 */
|
|
root: string,
|
|
}
|
|
|
|
/**
|
|
* 需要加载的分包配置接口
|
|
*/
|
|
export interface ILoadSubpackages extends ISubpackages {
|
|
/** 是否需要加载 */
|
|
ifLoad: boolean;
|
|
}
|
|
|
|
|
|
/**
|
|
* 游戏进入之前的加载基类
|
|
*/
|
|
export default abstract class BaseInitLoad {
|
|
|
|
loadPlanCallBack:(_i: number,length?:number)=>void = null;
|
|
loadItemsComCallBack:(_resLoad: ResLoadItem)=>void= null;
|
|
/** 分包列表,必须和分包配置文件中的列表一致 */
|
|
public subpackages: ILoadSubpackages[] = [
|
|
//{ name: "Presets", root: "Presets", ifLoad: true },
|
|
];
|
|
public constructor() {this._init();this.init();}
|
|
//初始化
|
|
private init() {
|
|
//执行加载之前的生命周期
|
|
this.loadBefore();
|
|
}
|
|
/**
|
|
* 游戏加载之前
|
|
* 可以在这里初始化一些东西
|
|
*/
|
|
protected loadBefore() { }
|
|
|
|
LodeOneBundle(name): Promise<any> {
|
|
return new Promise<void>((r, e) => {
|
|
ResLoad.Ins.loadBundle(name, (e, bundle) => {
|
|
//ResLoad.ResLodeBundle.set(name, bundle);
|
|
if (bundle) {
|
|
//ConsoleEx.Log("---------------加载Bundle成功@@ " + bundle.name);
|
|
r();
|
|
} else {
|
|
ConsoleEx.Error("加载Bundle失败@@", bundle);
|
|
}
|
|
});
|
|
});
|
|
}
|
|
/**
|
|
* 加载
|
|
* @param _comBack 加载完成回调
|
|
*/
|
|
public load(_comBack?: Function) {
|
|
this._loadBefore().then((()=>{
|
|
this._startLoadRed(this._getLoadItems(),_comBack)
|
|
}).bind(this));
|
|
}
|
|
|
|
|
|
// * --------
|
|
/**
|
|
* 初始化
|
|
*/
|
|
protected _init() { }
|
|
|
|
/**
|
|
* 游戏加载之前
|
|
* 可以在这里先加载一些东西
|
|
*/
|
|
protected _loadBefore(): Promise<any> {
|
|
return Promise.all(
|
|
this.subpackages.filter((item) => {
|
|
return item.ifLoad;
|
|
}).map((item) => {
|
|
return this.LodeOneBundle(item.name);
|
|
}));
|
|
}
|
|
|
|
protected _startLoadRed(_resLoadItems:ResLoadItem[],_comBack:Function){
|
|
ResLoadGroup.loadAsync(_resLoadItems, this._loadPlan.bind(this), this._loadItemsCom.bind(this)).then(()=>{
|
|
_comBack && _comBack();
|
|
});
|
|
}
|
|
|
|
/**
|
|
* 获取加载项列表
|
|
*/
|
|
protected _getLoadItems(): ResLoadItem[] {
|
|
return [];
|
|
}
|
|
|
|
/**
|
|
* 加载进度
|
|
* @param _i 进度值
|
|
*/
|
|
protected _loadPlan(_i: number,length?:number) {
|
|
this.loadPlanCallBack && this.loadPlanCallBack(_i,length);
|
|
}
|
|
|
|
/**
|
|
* 单个加载项完成回调
|
|
* @param _resLoad 加载项实例
|
|
*/
|
|
protected _loadItemsCom(_resLoad: ResLoadItem) {
|
|
this.loadItemsComCallBack && this.loadItemsComCallBack(_resLoad);
|
|
}
|
|
|
|
/**
|
|
* 加载完成
|
|
*/
|
|
protected _loadCom() { }
|
|
}
|