Options
All
  • Public
  • Public/Protected
  • All
Menu

Class PackManager

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

Hierarchy

  • PackManager

Index

Properties

Methods

Object literals

Properties

Private _loading

_loading: Cache<IUnpackRequest[]> = new Cache<IUnpackRequest[]>()

Methods

init

  • init(): void

load

  • load(item: RequestItem, options: IDownloadParseOptions | null, onComplete: CompleteCallback): void
  • 下载请求对象,如果请求对象不在任何包内,则正常下载,否则下载对应的 package 并进行拆解,并取回包内对应的内容

    example

    var requestItem = cc.AssetManager.RequestItem.create(); requestItem.uuid = 'fcmR3XADNLgJ1ByKhqcC5Z'; requestItem.info = config.getAssetInfo('fcmR3XADNLgJ1ByKhqcC5Z'); packManager.load(requestItem, null, (err, data) => console.log(err));

    Parameters

    • item: RequestItem

      Some item you want to download

    • options: IDownloadParseOptions | null

      Some optional parameters

    • onComplete: CompleteCallback

      Callback when finished

    Returns void

register

  • register(type: string, handler: Unpacker): void
  • register(map: Record<string, Unpacker>): void
  • 当你想修改默认行为或者拓展 packManager 来拆分其他格式的包时可以注册自定义的 handler

    example

    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), });

    Parameters

    • type: string

      Extension likes '.bin' or map likes {'.bin': binHandler, '.ab': abHandler}

    • handler: Unpacker

      handler

    Returns void

  • Parameters

    Returns void

unpack

  • unpack(pack: string[], data: any, type: string, options: IDownloadParseOptions, onComplete: CompleteCallback): void
  • 用对应的 handler 来进行解包

    method

    unpack

    example

    downloader.downloadFile('pack.json', {xhrResponseType: 'json'}, null, (err, file) => { packManager.unpack(['2fawq123d', '1zsweq23f'], file, '.json', null, (err, data) => console.log(err)); });

    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: IDownloadParseOptions

      Some optional parameter

    • onComplete: CompleteCallback

      callback when finishing unpacking

    Returns void

unpackJson

  • unpackJson(pack: string[], json: any, options: IDownloadParseOptions, onComplete: CompleteCallback<Record<string, any>>): void
  • 拆解 json 包,恢复为打包之前的内容

    example

    downloader.downloadFile('pack.json', { xhrResponseType: 'json'}, null, (err, file) => { packManager.unpackJson(['a', 'b'], file, null, (err, data) => console.log(err)); });

    Parameters

    • pack: string[]

      The pack

    • json: any

      The content of pack

    • options: IDownloadParseOptions

      Some optional parameters

    • onComplete: CompleteCallback<Record<string, any>>

      Callback when finish unpacking

    Returns void

Object literals

Private unpackers

unpackers: object

.json

.json: unpackJson = this.unpackJson

Generated using TypeDoc