1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- 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<any> = new Array<any>();
- /**资源包 */
- private static bundle: cc.AssetManager.Bundle = null;
- /**加载视窗资源 */
- public static loadViewResources (fguiRes: Array<string>, cocosRes: Array<string>,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<cc.Asset> = 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);
- }
- }
|