Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Downloader

Control all download process, it is a singleton. All member can be accessed with cc.assetManager.downloader , it can download several types of files:

  1. Text
  2. Image
  3. Audio
  4. Assets
  5. Scripts

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

The maximum number of concurrent when downloading

maxRequestsPerFrame

maxRequestsPerFrame: number = 16

The maximum number of request can be launched per frame when downloading

maxRetryCount

maxRetryCount: number = EDITOR ? 0 : 3

The max number of retries when fail

property

maxRetryCount

remoteBundles

remoteBundles: string[] = []

retryInterval

retryInterval: number = 2000

Wait for while before another retry, unit: ms

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
  • Use corresponding handler to download file under limitation

    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
  • Load sub package with name.

    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

  • Register custom handler if you want to change default behavior or extend downloader to download other format file

    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