PackManager Class

Module: cc.AssetManager

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

Index

Methods
  • unpackJson Unpack the json, revert to what it was before packing
  • register Register custom handler if you want to change default behavior or extend packManager to unpack other format pack
  • unpack Use corresponding handler to unpack package
  • load Download request item, If item is not in any package, download as usual.

Details

Methods

unpackJson

Unpack the json, revert to what it was before packing

meta description
Defined in cocos2d/core/asset-manager/pack-manager.js:57
Parameters
  • pack String[] The pack
  • json Object The content of pack
  • options Object Some optional parameters
  • onComplete Function Callback when finish unpacking
    • err Error The occurred error, null indicetes success
    • content Object The unpacked assets
Examples
downloader.downloadFile('pack.json', {responseType: 'json'}, null, (err, file) => {
     packManager.unpackJson(['a', 'b'], file, null, (err, data) => console.log(err));
});
register

Register custom handler if you want to change default behavior or extend packManager to unpack other format pack

meta description
Defined in cocos2d/core/asset-manager/pack-manager.js:121
Parameters
  • type string | Object Extension likes '.bin' or map likes {'.bin': binHandler, '.ab': abHandler}
  • handler Function handler
    • packUuid string The uuid of pack
    • data The content of pack
    • options Object Some optional parameters
    • onComplete Function Callback when finishing unpacking
Examples
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)});
unpack

Use corresponding handler to unpack package

meta description
Defined in cocos2d/core/asset-manager/pack-manager.js:153
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 Object Some optional parameter
  • onComplete Function callback when finishing unpacking
    • err Error The occurred error, null indicetes success
    • data Original assets
Examples
downloader.downloadFile('pack.json', {responseType: 'json'}, null, (err, file) => {
     packManager.unpack(['2fawq123d', '1zsweq23f'], file, '.json', null, (err, data) => console.log(err));
});
load

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.

meta description
Defined in cocos2d/core/asset-manager/pack-manager.js:186
Parameters
  • item RequestItem Some item you want to download
  • options Object Some optional parameters
  • onComplete Function Callback when finished
    • err Err The occurred error, null indicetes success
    • data The unpacked data retrieved from package
Examples
var requestItem = cc.AssetManager.RequestItem.create();
requestItem.uuid = 'fcmR3XADNLgJ1ByKhqcC5Z';
requestItem.info = config.getAssetInfo('fcmR3XADNLgJ1ByKhqcC5Z');
packManager.load(requestItem, null, (err, data) => console.log(err));

results matching ""

    No results matching ""