Options
All
  • Public
  • Public/Protected
  • All
Menu

Class PackManager

Handle the packed asset, include unpacking, loading, cache and so on. It is a singleton. All member can be accessed with cc.assetManager.packManager

Hierarchy

  • PackManager

Index

Properties

Methods

Object literals

Properties

Private _loading

_loading: Cache<IUnpackRequest[]> = new Cache<IUnpackRequest[]>()

Methods

init

  • init(): void

load

  • load(item: RequestItem, options: IDownloadParseOptions | null, onComplete: CompleteCallback): void
  • Download request item, If item is not in any package, download as usual. Otherwise, download the corresponding package and unpack it. And then retrieve the corresponding content form it.

    example

    var requestItem = cc.AssetManager.RequestItem.create(); requestItem.uuid = 'fcmR3XADNLgJ1ByKhqcC5Z'; requestItem.info = config.getAssetInfo('fcmR3XADNLgJ1ByKhqcC5Z'); packManager.load(requestItem, null, (err, data) => console.log(err));

    Parameters

    • item: RequestItem

      Some item you want to download

    • options: IDownloadParseOptions | null

      Some optional parameters

    • onComplete: CompleteCallback

      Callback when finished

    Returns void

register

  • register(type: string, handler: Unpacker): void
  • register(map: Record<string, Unpacker>): void
  • Register custom handler if you want to change default behavior or extend packManager to unpack other format pack

    example

    packManager.register('.bin', (packUuid, file, options, onComplete) => onComplete(null, null)); packManager.register({ '.bin': (packUuid, file, options, onComplete) => onComplete(null, null), '.ab': (packUuid, file, options, onComplete) => onComplete(null, null), });

    Parameters

    • type: string

      Extension likes '.bin' or map likes {'.bin': binHandler, '.ab': abHandler}

    • handler: Unpacker

      handler

    Returns void

  • Parameters

    Returns void

unpack

  • unpack(pack: string[], data: any, type: string, options: IDownloadParseOptions, onComplete: CompleteCallback): void
  • Use corresponding handler to unpack package

    method

    unpack

    example

    downloader.downloadFile('pack.json', {xhrResponseType: 'json'}, null, (err, file) => { packManager.unpack(['2fawq123d', '1zsweq23f'], file, '.json', null, (err, data) => console.log(err)); });

    Parameters

    • pack: string[]

      The uuid of packed assets

    • data: any

      The packed data

    • type: string

      The type indicates that which handler should be used to download, such as '.jpg'

    • options: IDownloadParseOptions

      Some optional parameter

    • onComplete: CompleteCallback

      callback when finishing unpacking

    Returns void

unpackJson

  • unpackJson(pack: string[], json: any, options: IDownloadParseOptions, onComplete: CompleteCallback<Record<string, any>>): void
  • Unpack the json, revert to what it was before packing

    example

    downloader.downloadFile('pack.json', { xhrResponseType: 'json'}, null, (err, file) => { packManager.unpackJson(['a', 'b'], file, null, (err, data) => console.log(err)); });

    Parameters

    • pack: string[]

      The pack

    • json: any

      The content of pack

    • options: IDownloadParseOptions

      Some optional parameters

    • onComplete: CompleteCallback<Record<string, any>>

      Callback when finish unpacking

    Returns void

Object literals

Private unpackers

unpackers: object

.json

.json: unpackJson = this.unpackJson

Generated using TypeDoc