MaterialUtil.ts 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import { isValid, Sprite, SpriteAtlas, SpriteFrame } from "cc"
  2. import { AssetType, resLoader } from "../res/ResLoader"
  3. import { AsyncQueue, NextFunction } from "../queue/AsyncQueue";
  4. //头像类型
  5. export enum HeadSpriteType{
  6. //圆形
  7. Critical = 0,
  8. //方块
  9. Square,
  10. //圆角
  11. Round,
  12. }
  13. export class MaterialUtil {
  14. static iconGame: SpriteAtlas = null;
  15. static iconFilter: SpriteAtlas = null;
  16. //头像
  17. static iconHead: SpriteFrame = null;
  18. static Restart() {
  19. }
  20. static init(callback) {
  21. let queue = new AsyncQueue();
  22. queue.pushMulti("InitPool", async (next: NextFunction, params: any, args: any) => {
  23. resLoader.load('package', 'texture/head/end_0_1/spriteFrame', SpriteFrame, (error: Error, res: SpriteFrame) => {
  24. if (!error) {
  25. this.iconHead = res;
  26. if(callback) callback();
  27. next()
  28. console.log('头像图标加载完成');
  29. }
  30. });
  31. // }, async (next: NextFunction, params: any, args: any) => {
  32. // resLoader.load('package', 'texture/hall/Games/Icon_Filter', SpriteAtlas, (error: Error, res: SpriteAtlas) => {
  33. // if (!error) {
  34. // this.iconFilter = res;
  35. // if(callback) callback();
  36. // next()
  37. // console.log('游戏筛选图标加载完成');
  38. // }
  39. // });
  40. });
  41. queue.complete = () => {
  42. console.log('materialUtil初始化完成');
  43. };
  44. queue.play();
  45. }
  46. _loadRes(LoadType: AssetType, Url, Back) {
  47. resLoader.load('package', Url, LoadType, (error: Error, res) => {
  48. if (!error) {
  49. Back(res)
  50. }
  51. });
  52. }
  53. // /** 游戏入口图标 */
  54. // static getIconGameByID(id) {
  55. // return this.iconGame.spriteFrames[id];
  56. // }
  57. // /** 游戏筛选图标 */
  58. // static getIconFilterByName(name) {
  59. // return this.iconFilter.spriteFrames[name];
  60. // }
  61. /** 游戏入口图标 */
  62. static getHeadByID(id,sprite:Sprite,headType:HeadSpriteType = HeadSpriteType.Critical) {
  63. resLoader.load('package', 'texture/head/end_0_'+id+"/spriteFrame", SpriteFrame, (error: Error, res: SpriteFrame) => {
  64. if (!error && isValid(sprite)) {
  65. sprite.spriteFrame = res;
  66. }
  67. })
  68. //return this.iconGame.spriteFrames[id];
  69. }
  70. }