Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Downloader

管理所有下载过程,downloader 是个单例,所有成员能通过 cc.assetManager.downloader 访问,它能下载以下几种类型的文件:

  1. 文本
  2. 图片
  3. 音频
  4. 资源
  5. 脚本

Hierarchy

  • Downloader

Index

Properties

Private _checkNextPeriod

_checkNextPeriod: boolean = false

Private downloading

downloading: Cache<((err: Error | null, data?: T | null) => void)[]> = new Cache<CompleteCallback[]>()

Private _lastDate

_lastDate: number = -1

Private _maxInterval

_maxInterval: number = 1 / 30

Private _queue

_queue: IDownloadRequest[] = []

Private _queueDirty

_queueDirty: boolean = false

Private _remoteServerAddress

_remoteServerAddress: string = ""

Private _totalNum

_totalNum: number = 0

Private _totalNumThisPeriod

_totalNumThisPeriod: number = 0

appendTimeStamp

appendTimeStamp: boolean = !!EDITOR

bundleVers

bundleVers: Record<string, string> | null = null

downloadDomAudio

downloadDomAudio: DownloadHandler | null = null

downloadDomImage

downloadDomImage: downloadDomImage = downloadDomImage

downloadFile

downloadFile: downloadFile = downloadFile

downloadScript

downloadScript: downloadScript = downloadScript

limited

limited: boolean = !EDITOR

maxConcurrency

maxConcurrency: number = 16

下载时的最大并发数

maxRequestsPerFrame

maxRequestsPerFrame: number = 16

下载时每帧可以启动的最大请求数

maxRetryCount

maxRetryCount: number = EDITOR ? 0 : 3

失败重试次数

property

maxRetryCount

remoteBundles

remoteBundles: string[] = []

retryInterval

retryInterval: number = 2000

重试的间隔时间

Accessors

remoteServerAddress

  • get remoteServerAddress(): string

Methods

Private handleQueue

  • handleQueue(maxConcurrency: number, maxRequestsPerFrame: number): void

Private handleQueueInNextFrame

  • handleQueueInNextFrame(maxConcurrency: number, maxRequestsPerFrame: number): void

Private updateTime

  • _updateTime(): void

download

  • download(id: string, url: string, type: string, options: IDownloadParseOptions, onComplete: CompleteCallback): void
  • 在限制下使用对应的 handler 来下载文件

    example

    download('http://example.com/test.tga', '.tga', {onFileProgress: (loaded, total) => console.lgo(loaded/total)}, onComplete: (err) => console.log(err));

    Parameters

    • id: string

      The unique id of this download

    • url: string

      The url should be downloaded

    • type: string

      The type indicates that which handler should be used to download, such as '.jpg'

    • options: IDownloadParseOptions

      some optional paramters will be transferred to the corresponding handler.

    • onComplete: CompleteCallback

      callback when finishing downloading

    Returns void

importBundleEntry

  • importBundleEntry(bundleName: string): Promise<any>

init

  • init(remoteServerAddress?: string, bundleVers?: Record<string, string>, remoteBundles?: string[]): void
  • Parameters

    • Default value remoteServerAddress: string = ""
    • Default value bundleVers: Record<string, string> = {}
    • Default value remoteBundles: string[] = []

    Returns void

loadSubpackage

  • loadSubpackage(name: string, completeCallback?: CompleteCallbackNoData): void
  • 通过子包名加载子包代码。

    deprecated

    loader.downloader.loadSubpackage is deprecated, please use AssetManager.loadBundle instead

    Parameters

    • name: string

      Sub package name

    • Optional completeCallback: CompleteCallbackNoData

      Callback invoked when sub package loaded

    Returns void

register

  • 当你想修改默认行为或者拓展 downloader 来下载其他格式文件时可以注册自定义的 handler

    example

    downloader.register('.tga', (url, options, onComplete) => onComplete(null, null)); downloader.register({'.tga': (url, options, onComplete) => onComplete(null, null), '.ext': (url, options, onComplete) => onComplete(null, null)});

    Parameters

    • type: string

      Extension likes '.jpg' or map likes {'.jpg': jpgHandler, '.png': pngHandler}

    • handler: DownloadHandler

      handler

    Returns void

  • Parameters

    Returns void

Object literals

Private downloaders

downloaders: object

.ExportJson

.ExportJson: downloadJson = downloadJson

.astc

.astc: downloadArrayBuffer = downloadArrayBuffer

.atlas

.atlas: downloadText = downloadText

.bin

.bin: downloadArrayBuffer = downloadArrayBuffer

.binary

.binary: downloadArrayBuffer = downloadArrayBuffer

.bmp

.bmp: downloadImage = downloadImage

.dbbin

.dbbin: downloadArrayBuffer = downloadArrayBuffer

.fnt

.fnt: downloadText = downloadText

.fsh

.fsh: downloadText = downloadText

.gif

.gif: downloadImage = downloadImage

.ico

.ico: downloadImage = downloadImage

.image

.image: downloadImage = downloadImage

.jpeg

.jpeg: downloadImage = downloadImage

.jpg

.jpg: downloadImage = downloadImage

.js

.js: downloadScript = downloadScript

.json

.json: downloadJson = downloadJson

.pkm

.pkm: downloadArrayBuffer = downloadArrayBuffer

.plist

.plist: downloadText = downloadText

.png

.png: downloadImage = downloadImage

.pvr

.pvr: downloadArrayBuffer = downloadArrayBuffer

.skel

.skel: downloadArrayBuffer = downloadArrayBuffer

.tiff

.tiff: downloadImage = downloadImage

.tmx

.tmx: downloadText = downloadText

.tsx

.tsx: downloadText = downloadText

.txt

.txt: downloadText = downloadText

.vsh

.vsh: downloadText = downloadText

.webp

.webp: downloadImage = downloadImage

.xml

.xml: downloadText = downloadText

bundle

bundle: downloadBundle = downloadBundle

default

default: downloadText = downloadText

Generated using TypeDoc