PackManager
类型
模块: cc.AssetManager
处理打包资源,包括拆包,加载,缓存等等,这是一个单例, 所有成员能通过 cc.assetManager.packManager
访问
索引
方法
unpackJson
拆解 json 包,恢复为打包之前的内容register
当你想修改默认行为或者拓展 packManager 来拆分其他格式的包时可以注册自定义的 handlerunpack
用对应的 handler 来进行解包load
下载请求对象,如果请求对象不在任何包内,则正常下载,否则下载对应的 package 并进行拆解,并取回包内对应的内容
Details
方法
unpackJson
拆解 json 包,恢复为打包之前的内容
meta | description |
---|---|
定义于 | cocos2d/core/asset-manager/pack-manager.js:57 |
参数列表
pack
String[] The packjson
Object The content of packoptions
Object Some optional parametersonComplete
Function Callback when finish unpacking
示例
downloader.downloadFile('pack.json', {responseType: 'json'}, null, (err, file) => {
packManager.unpackJson(['a', 'b'], file, null, (err, data) => console.log(err));
});
register
当你想修改默认行为或者拓展 packManager 来拆分其他格式的包时可以注册自定义的 handler
meta | description |
---|---|
定义于 | cocos2d/core/asset-manager/pack-manager.js:121 |
参数列表
type
string | Object Extension likes '.bin' or map likes {'.bin': binHandler, '.ab': abHandler}handler
Function handler
示例
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
用对应的 handler 来进行解包
meta | description |
---|---|
定义于 | cocos2d/core/asset-manager/pack-manager.js:153 |
参数列表
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
示例
downloader.downloadFile('pack.json', {responseType: 'json'}, null, (err, file) => {
packManager.unpack(['2fawq123d', '1zsweq23f'], file, '.json', null, (err, data) => console.log(err));
});
load
下载请求对象,如果请求对象不在任何包内,则正常下载,否则下载对应的 package 并进行拆解,并取回包内对应的内容
meta | description |
---|---|
定义于 | cocos2d/core/asset-manager/pack-manager.js:186 |
参数列表
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
示例
var requestItem = cc.AssetManager.RequestItem.create();
requestItem.uuid = 'fcmR3XADNLgJ1ByKhqcC5Z';
requestItem.info = config.getAssetInfo('fcmR3XADNLgJ1ByKhqcC5Z');
packManager.load(requestItem, null, (err, data) => console.log(err));