import { assetManager, isValid, Sprite, SpriteAtlas, SpriteFrame } from "cc" import { AssetType, resLoader } from "../res/ResLoader" import { AsyncQueue, NextFunction } from "../queue/AsyncQueue"; //头像类型 export enum HeadSpriteType{ //圆形 Critical = 0, //方块 Square, //圆角 Round, } //进度数据 export interface ProcessData{ curMain: number; maxMain: number; curSub: number; maxSub: number; } export class MaterialUtil { static iconGame: SpriteAtlas = null; static iconFilter: SpriteAtlas = null; //头像 static iconHead: SpriteFrame = null; static Restart() { } static init(callback) { let queue = new AsyncQueue(); let process:ProcessData = { curMain: 0, maxMain: 0, curSub: 0, maxSub: 0 } queue.pushMulti("InitPool", async (next: NextFunction, params: any, args: any) => { resLoader.load('package', 'texture/head/end_0_1/spriteFrame', SpriteFrame, // (finished: number, total: number)=>{ // process.curSub = finished; // process.maxSub = total; // if(callback) callback(process); // }, (error: Error, res: SpriteFrame) => { if (!error) { this.iconHead = res; process.curMain++ if(callback) callback(process); next() console.log('头像图标加载完成'); } }); }, async (next: NextFunction, params: any, args: any) => { assetManager.loadBundle("common", // {onFileProgress: (finished: number, total: number)=>{ // process.curSub = finished; // process.maxSub = total; // if(callback) callback(process); // }}, (err, bundle)=>{ if (!err) { process.curMain++ if(callback) callback(process); next() console.log('游戏筛选图标加载完成:',queue.size); } }); }, async (next: NextFunction, params: any, args: any) => { assetManager.loadBundle("duplicate", // {onFileProgress: (finished: number, total: number)=>{ // process.curSub = finished; // process.maxSub = total; // if(callback) callback(process); // }}, (err, bundle)=>{ if (!err) { process.curMain++ if(callback) callback(process); next() console.log('游戏筛选图标加载完成:',queue.size); } }); }); process.maxMain = 3; queue.complete = () => { console.log('materialUtil初始化完成'); }; queue.play(); } _loadRes(LoadType: AssetType, Url, Back) { resLoader.load('package', Url, LoadType, (error: Error, res) => { if (!error) { Back(res) } }); } // /** 游戏入口图标 */ // static getIconGameByID(id) { // return this.iconGame.spriteFrames[id]; // } // /** 游戏筛选图标 */ // static getIconFilterByName(name) { // return this.iconFilter.spriteFrames[name]; // } /** 游戏入口图标 */ static getHeadByID(id,sprite:Sprite,headType:HeadSpriteType = HeadSpriteType.Critical) { resLoader.load('package', 'texture/head/end_0_'+id+"/spriteFrame", SpriteFrame, (error: Error, res: SpriteFrame) => { if (!error && isValid(sprite)) { sprite.spriteFrame = res; } }) //return this.iconGame.spriteFrames[id]; } }