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 packingregister
Register custom handler if you want to change default behavior or extend packManager to unpack other format packunpack
Use corresponding handler to unpack packageload
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 packjson
Object The content of packoptions
Object Some optional parametersonComplete
Function 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
type
string | Object Extension likes '.bin' or map likes {'.bin': binHandler, '.ab': abHandler}handler
Function 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
pack
String[] The uuid of packed assetsdata
Any The packed datatype
string The type indicates that which handler should be used to download, such as '.jpg'options
Object Some optional parameteronComplete
Function callback when finishing unpackingerr
Error The occurred error, null indicetes successdata
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 downloadoptions
Object Some optional parametersonComplete
Function Callback when finishederr
Err The occurred error, null indicetes successdata
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));