import EventManager from "../Event/EventManager"; import { _EJsonRes } from "../Data/CommonDataType"; import { EventName } from "../Event/EventName"; import Tool from "../Tool/Tool"; /** * 视窗资源 - 数据层 */ export default class ViewResources { /**资源列表 */ private static resources: Array = new Array(); /**资源包 */ private static bundle: cc.AssetManager.Bundle = null; /**加载视窗资源 */ public static loadViewResources (fguiRes: Array, cocosRes: Array,denominator: number, currentProgress: number, callback: Function) { Tool.log("加载视窗资源"); let fguiMax: number = fguiRes.length-1; let imageMax: number = cocosRes.length; let max: number = fguiMax+imageMax; let count: number = 0; let loadCocosRes = () => { cc.assetManager.loadBundle("res/cocos", (err: Error, cocos: cc.AssetManager.Bundle) => { this.bundle = cocos; this.bundle.load(cocosRes, cc.SpriteFrame, (finish: number, total: number, item: cc.AssetManager.RequestItem) => { // 发送初始加载进度 本地消息 EventManager.sendEvent(EventName.Res.Res_LoadProgress, (count/max)*denominator + currentProgress); count++; }, (err: Error, assets: cc.Asset[]) => { Tool.log(err); let cocos: Array = this.resources["cocos"] || []; for (let i in assets) { cocos[assets[i].name] = assets[i]; } this.resources["cocos"] = cocos; Tool.log(this.resources); Tool.log("加载完毕"); Tool.log(""); if (callback == null) { // 发送初始加载完成 本地消息 EventManager.sendEvent(EventName.Res.Res_LoadComplete); } else { callback(); } } ); }); } if (fguiRes.length > 0) { cc.assetManager.loadBundle("res/fgui", (err: Error, bundle: cc.AssetManager.Bundle) => { for (let j: number = 0; j < fguiRes.length; j++) { fgui.UIPackage.loadPackage(bundle, fguiRes[j], (err, data: fgui.UIPackage) => { Tool.log(err); this.resources.push(data); if (count < fguiMax) { // 发送初始加载进度 本地消息 EventManager.sendEvent(EventName.Res.Res_LoadProgress, (count/max)*denominator + currentProgress); } else { loadCocosRes(); } count++; } ); } }); } else { loadCocosRes(); } } /**获得视窗资源 */ public static getResources (name: string): any { let _name: string = name; if (name.includes("/") == true) { _name = name.substring(name.indexOf("/")+1); } return this.resources["cocos"][_name] || this.bundle.get(name); } }