Options
All
  • Public
  • Public/Protected
  • All
Menu

Class AssetManager

This module controls asset's behaviors and information, include loading, releasing etc. it is a singleton All member can be accessed with cc.assetManager.

Hierarchy

  • AssetManager

Index

Properties

Private _files

_files: Cache<any> = files

Private _parsePipeline

_parsePipeline: null | Pipeline = BUILD ? null : new Pipeline('parse existing json', [this.loadPipe])

Private _parsed

_parsed: Cache<any> = parsed

Private _releaseManager

_releaseManager: ReleaseManager = releaseManager

allowImageBitmap

allowImageBitmap: boolean = !sys.isMobile

Whether to use image bitmap to load image first. If enabled, images loading will become faster but memory usage will increase.

assets

assets: Cache<Asset> = assets

The collection of asset which is already loaded, you can remove cache with {{#crossLink "AssetManager/releaseAsset:method"}}{{/crossLink}}

bundles

bundles: Cache<Bundle> = bundles

The collection of bundle which is already loaded, you can remove cache with {{#crossLink "AssetManager/removeBundle:method"}}{{/crossLink}}

cacheAsset

cacheAsset: boolean = true

Whether or not cache the loaded asset

cacheManager

cacheManager: CacheManager | null = null

Cache manager is a module which controls all caches downloaded from server in non-web platform.

dependUtil

dependUtil: DependUtil = dependUtil

Manage relationship between asset and its dependencies

downloader

downloader: Downloader = downloader

Manage all downloading task

factory

factory: Factory = factory

fetchPipe

fetchPipe: IPipe = fetch

fetchPipeline

fetchPipeline: Pipeline = fetchPipeline.append(preprocess).append(fetch)

Fetching pipeline

force

force: boolean = !!EDITOR

Whether or not load asset forcely, if it is true, asset will be loaded regardless of error

generalImportBase

generalImportBase: string = ""

generalNativeBase

generalNativeBase: string = ""

loadPipe

loadPipe: IPipe = load

packManager

packManager: PackManager = packManager

Manage all packed asset

parser

parser: Parser = parser

Manage all parsing task

pipeline

pipeline: Pipeline = pipeline.append(preprocess).append(load)

Normal loading pipeline

preprocessPipe

preprocessPipe: IPipe = preprocess

presets

presets: {} = presets

The preset of options

Type declaration

references

references: null | Cache<any[]> = references

transformPipeline

transformPipeline: Pipeline = transformPipeline.append(parse).append(combine)

Url transformer

utils

utils: "D:/workCode/editor-3d/resources/3d/engine/cocos/core/asset-manager/helper" = helper

Some useful function

Accessors

main

resources

  • get resources(): Bundle | null

Methods

getBundle

  • getBundle(name: string): Bundle | null
  • Get the bundle which has been loaded

    example

    // ${project}/assets/test1 cc.assetManager.getBundle('test1'); cc.assetManager.getBundle('resources');

    Parameters

    • name: string

      The name of bundle

    Returns Bundle | null

    • The loaded bundle

init

loadAny

  • loadAny(requests: Request, options: IOptions | null, onProgress: ProgressCallback | null, onComplete: CompleteCallbackWithData | null): void
  • loadAny(requests: Request, onProgress: ProgressCallback | null, onComplete: CompleteCallbackWithData | null): void
  • loadAny(requests: Request, options: IOptions | null, onComplete?: CompleteCallbackWithData | null): void
  • loadAny<T>(requests: string, onComplete?: CompleteCallbackWithData<T> | null): void
  • loadAny<T>(requests: string[], onComplete?: CompleteCallbackWithData<T[]> | null): void
  • loadAny(requests: Request, onComplete?: CompleteCallbackWithData | null): void
  • General interface used to load assets with a progression callback and a complete callback. You can achieve almost all effect you want with combination of requests and options.It is highly recommended that you use more simple API, such as load, loadDir etc. Every custom parameter in options will be distribute to each of requests. if request already has same one, the parameter in request will be given priority. Besides, if request has dependencies, options will distribute to dependencies too. Every custom parameter in requests will be tranfered to handler of downloader and parser as options. You can register you own handler downloader or parser to collect these custom parameters for some effect.

    Reserved Keyword: uuid, url, path, dir, scene, type, priority, preset, audioLoadMode, ext, bundle, onFileProgress, maxConcurrency, maxRequestsPerFrame, maxRetryCount, version, xhrResponseType, xhrWithCredentials, xhrMimeType, xhrTimeout, xhrHeader, reloadAsset, cacheAsset, cacheEnabled, Please DO NOT use these words as custom options!

    example

    cc.assetManager.loadAny({url: 'http://example.com/a.png'}, (err, img) => cc.log(img)); cc.assetManager.loadAny(['60sVXiTH1D/6Aft4MRt9VC'], (err, assets) => cc.log(assets)); cc.assetManager.loadAny([{ uuid: '0cbZa5Y71CTZAccaIFluuZ'}, {url: 'http://example.com/a.png'}], (err, assets) => cc.log(assets)); cc.assetManager.downloader.register('.asset', (url, options, onComplete) => { url += '?userName=' + options.userName + "&password=" + options.password; cc.assetManager.downloader.downloadFile(url, null, onComplete); }); cc.assetManager.parser.register('.asset', (file, options, onComplete) => { var json = JSON.parse(file); var skin = json[options.skin]; var model = json[options.model]; onComplete(null, {skin, model}); }); cc.assetManager.loadAny({ url: 'http://example.com/my.asset', skin: 'xxx', model: 'xxx', userName: 'xxx', password: 'xxx' });

    Parameters

    • requests: Request

      The request you want to load

    • options: IOptions | null

      Optional parameters

    • onProgress: ProgressCallback | null

      Callback invoked when progression change

    • onComplete: CompleteCallbackWithData | null

      Callback invoked when finish loading

    Returns void

  • Parameters

    • requests: Request
    • onProgress: ProgressCallback | null
    • onComplete: CompleteCallbackWithData | null

    Returns void

  • Parameters

    • requests: Request
    • options: IOptions | null
    • Optional onComplete: CompleteCallbackWithData | null

    Returns void

  • Type parameters

    Parameters

    • requests: string
    • Optional onComplete: CompleteCallbackWithData<T> | null

    Returns void

  • Type parameters

    Parameters

    • requests: string[]
    • Optional onComplete: CompleteCallbackWithData<T[]> | null

    Returns void

  • Parameters

    • requests: Request
    • Optional onComplete: CompleteCallbackWithData | null

    Returns void

loadBundle

  • loadBundle(nameOrUrl: string, options: IBundleOptions | null, onComplete?: CompleteCallbackWithData<Bundle> | null): void
  • loadBundle(nameOrUrl: string, onComplete?: CompleteCallbackWithData<Bundle> | null): void

loadRemote

  • loadRemote<T>(url: string, options: IRemoteOptions | null, onComplete?: CompleteCallbackWithData<T> | null): void
  • loadRemote<T>(url: string, onComplete?: CompleteCallbackWithData<T> | null): void

Private loadWithJson

  • loadWithJson<T>(json: Record<string, any>, options: IJsonAssetOptions | null, onProgress: ProgressCallback | null, onComplete: CompleteCallbackWithData<T> | null): void
  • loadWithJson<T>(json: Record<string, any>, onProgress: ProgressCallback | null, onComplete: CompleteCallbackWithData<T> | null): void
  • loadWithJson<T>(json: Record<string, any>, options: IJsonAssetOptions | null, onComplete?: CompleteCallbackWithData<T> | null): void
  • loadWithJson<T>(json: Record<string, any>, onComplete?: CompleteCallbackWithData<T> | null): void

postLoadNative

  • postLoadNative(asset: Asset, options: INativeAssetOptions | null, onComplete: CompleteCallbackNoData | null): void
  • postLoadNative(asset: Asset, onComplete?: CompleteCallbackNoData | null): void
  • Load native file of asset, if you check the option 'Async Load Assets', you may need to load native file with this before you use the asset

    example

    cc.assetManager.postLoadNative(texture, (err) => console.log(err));

    Parameters

    • asset: Asset

      The asset

    • options: INativeAssetOptions | null

      Some optional parameters

    • onComplete: CompleteCallbackNoData | null

      Callback invoked when finish loading

    Returns void

  • Parameters

    • asset: Asset
    • Optional onComplete: CompleteCallbackNoData | null

    Returns void

preloadAny

  • preloadAny(requests: Request, options: IOptions | null, onProgress: ProgressCallback | null, onComplete: CompleteCallbackWithData<RequestItem[]> | null): void
  • preloadAny(requests: Request, onProgress: ProgressCallback | null, onComplete: CompleteCallbackWithData<RequestItem[]> | null): void
  • preloadAny(requests: Request, options: IOptions | null, onComplete?: CompleteCallbackWithData<RequestItem[]> | null): void
  • preloadAny(requests: Request, onComplete?: CompleteCallbackWithData<RequestItem[]> | null): void
  • General interface used to preload assets with a progression callback and a complete callback.It is highly recommended that you use more simple API, such as preloadRes, preloadResDir etc. Everything about preload is just likes cc.assetManager.loadAny, the difference is cc.assetManager.preloadAny will only download asset but not parse asset. You need to invoke cc.assetManager.loadAny(preloadTask) to finish loading asset

    example

    cc.assetManager.preloadAny('0cbZa5Y71CTZAccaIFluuZ', (err) => cc.assetManager.loadAny('0cbZa5Y71CTZAccaIFluuZ'));

    Parameters

    • requests: Request

      The request you want to preload

    • options: IOptions | null

      Optional parameters

    • onProgress: ProgressCallback | null

      Callback invoked when progression change

    • onComplete: CompleteCallbackWithData<RequestItem[]> | null

      Callback invoked when finish preloading

    Returns void

  • Parameters

    • requests: Request
    • onProgress: ProgressCallback | null
    • onComplete: CompleteCallbackWithData<RequestItem[]> | null

    Returns void

  • Parameters

    • requests: Request
    • options: IOptions | null
    • Optional onComplete: CompleteCallbackWithData<RequestItem[]> | null

    Returns void

  • Parameters

    • requests: Request
    • Optional onComplete: CompleteCallbackWithData<RequestItem[]> | null

    Returns void

releaseAll

  • releaseAll(): void

releaseAsset

  • releaseAsset(asset: Asset): void
  • Release asset and it's dependencies. This method will not only remove the cache of the asset in assetManager, but also clean up its content. For example, if you release a texture, the texture asset and its gl texture data will be freed up. Notice, this method may cause the texture to be unusable, if there are still other nodes use the same texture, they may turn to black and report gl errors.

    example

    // release a texture which is no longer need cc.assetManager.releaseAsset(texture);

    Parameters

    • asset: Asset

      The asset to be released

    Returns void

removeBundle

  • removeBundle(bundle: Bundle): void
  • Remove this bundle. NOTE: The asset whthin this bundle will not be released automatically, you can call {{#crossLink "Bundle/releaseAll:method"}}{{/crossLink}} manually before remove it if you need

    typescript

    removeBundle(bundle: cc.AssetManager.Bundle): void

    Parameters

    • bundle: Bundle

      The bundle to be removed

    Returns void

Generated using TypeDoc