import { EBundleName } from "../const/GameEnum"; import ResLoad, { CCAssetType } from "./ResLoad"; /** * 资源加载项 * 负责一组资源列表的加载 */ export default class ResLoadItem{ /** 加载模式 */ private m_loadBundle: EBundleName |string; private type:CCAssetType; /** 加载关键键值 */ private m_key: any; /** 加载完成回调 */ private m_comBack: any; /** 加载进度回调 */ private m_onProgress: any; /** 资源路径列表 */ private m_res: any; /** 获取关键键值 */ public get key(): any { return this.m_key; } /** * 初始化 * @param _res 资源列表 * @param _mode 加载模式 * @param _key 关键键值 * @param _comBack 加载完成时的回调函数 * @param _onProgress 加载进度回调 */ public constructor(_res: any, _mode: EBundleName|string,type:CCAssetType, _key?: any, _comBack?: Function, _onProgress?: Function) { this.m_res = _res; this.type = type; this.m_loadBundle = _mode; this.m_key = _key; this.m_comBack = _comBack; this.m_onProgress = _onProgress; } /** * 加载资源 * @param onCompleted 完成时回调 * @param _onProgress 加载进度回调 */ public load(onCompleted: any, _onProgress?: any) { //包装进度回调 let __onProgress: any = _onProgress; if (__onProgress && this.m_onProgress) { __onProgress = (this, (i) => { _onProgress(i); this.m_onProgress(i); }); } else if (this.m_onProgress) { __onProgress = this.m_onProgress; } if (this.m_comBack) { if (!onCompleted) { ResLoad.Ins.Load(this.m_res, this.m_loadBundle, this.type, this.m_comBack, __onProgress); } else { ResLoad.Ins.Load(this.m_res, this.m_loadBundle, this.type, ((e, res) => { this.m_comBack(e, res); onCompleted(e, res); }).bind(this), __onProgress); } } else { ResLoad.Ins.Load(this.m_res,this.m_loadBundle,this.type, onCompleted, __onProgress); } } /** * 异步加载资源 * @param _onProgress 加载进度回调 */ public loadAsync(_onProgress?: Function): Promise { return new Promise((r) => { this.load(( () => { r(); }).bind(this), _onProgress); }); } }