ResourceManager.ts 870 B

12345678910111213141516171819202122232425262728293031323334353637
  1. /** @format */
  2. import {Data, Mgr} from '../GameControl'
  3. import {Log} from '../utils/LogUtils'
  4. /** @format */
  5. export class ResourceManager {
  6. public init() {
  7. if (Mgr.platform.isWeChat()) {
  8. // @ts-ignore
  9. wx.onMemoryWarning(() => {
  10. Log.warn('MemoryWarning!start gc')
  11. Mgr.platform.gc()
  12. })
  13. }
  14. }
  15. public dumpSize() {
  16. cc.assetManager.assets.forEach((value: cc.Asset, key) => {
  17. console.log(value, key)
  18. })
  19. }
  20. loadTexSync(url: string) {
  21. return new Promise((resolve, reject) => {
  22. Data.main.texBundle.load(url, cc.SpriteFrame, (err, sp: cc.SpriteFrame) => {
  23. if (err) {
  24. reject(null)
  25. } else {
  26. resolve(sp)
  27. }
  28. })
  29. })
  30. }
  31. }