1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- /** @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<T extends cc.Asset>(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<T extends cc.Asset>(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)
- }
- })
- })
- }
- }
|