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
unpackJsonUnpack the json, revert to what it was before packingregisterRegister custom handler if you want to change default behavior or extend packManager to unpack other format packunpackUse corresponding handler to unpack packageloadDownload 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
packString[] The packjsonObject The content of packoptionsObject Some optional parametersonCompleteFunction Callback when finish unpacking
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
typestring | Object Extension likes '.bin' or map likes {'.bin': binHandler, '.ab': abHandler}handlerFunction handler
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
packString[] The uuid of packed assetsdataAny The packed datatypestring The type indicates that which handler should be used to download, such as '.jpg'optionsObject Some optional parameteronCompleteFunction callback when finishing unpackingerrError The occurred error, null indicetes successdataOriginal 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
itemRequestItem Some item you want to downloadoptionsObject Some optional parametersonCompleteFunction Callback when finishederrErr The occurred error, null indicetes successdataThe 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));