/** @format */ import {Data, Mgr} from '../GameControl' import {Log} from '../utils/LogUtils' /** @format */ export class ResourceManager { public init() { if (Mgr.platform.isWeChat()) { // @ts-ignore wx.onMemoryWarning(() => { Log.warn('MemoryWarning!start gc') Mgr.platform.gc() }) } } public dumpSize() { cc.assetManager.assets.forEach((value: cc.Asset, key) => { console.log(value, key) }) } async loadTexSync(url: string) { let sf = await this.loadSync(Data.main.texBundle, url, cc.SpriteFrame) return sf } //同步加载 public loadSync(bundle: cc.AssetManager.Bundle, url: string, type: typeof cc.Asset) { return new Promise((resolve: (asset: T) => void, reject) => { bundle.load(url, type, (err, asset: T) => { if (err) { resolve(null) } else { resolve(asset) } }) }) } //同步加载 public loadDirSync(bundle: cc.AssetManager.Bundle, url: string, type: typeof cc.Asset) { return new Promise((resolve: (asset: T[]) => void, reject) => { bundle.loadDir(url, type, (err, asset: T[]) => { if (err) { resolve(null) } else { resolve(asset) } }) }) } }