PackManager 类型

模块: cc.AssetManager

处理打包资源,包括拆包,加载,缓存等等,这是一个单例, 所有成员能通过 cc.assetManager.packManager 访问

索引

方法
  • unpackJson 拆解 json 包,恢复为打包之前的内容
  • register 当你想修改默认行为或者拓展 packManager 来拆分其他格式的包时可以注册自定义的 handler
  • unpack 用对应的 handler 来进行解包
  • load 下载请求对象,如果请求对象不在任何包内,则正常下载,否则下载对应的 package 并进行拆解,并取回包内对应的内容

Details

方法

unpackJson

拆解 json 包,恢复为打包之前的内容

meta description
定义于 cocos2d/core/asset-manager/pack-manager.js:57
参数列表
  • 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
示例
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
    • packUuid string The uuid of pack
    • data The content of pack
    • options Object Some optional parameters
    • onComplete Function Callback when finishing unpacking
示例
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 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
示例
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 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
示例
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 ""