Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Bundle

一个包含一定数量资源(包括场景)的包,你可以加载,预加载,释放此包内的资源

Hierarchy

  • Bundle

Index

Properties

Private _config

_config: Config = new Config()

Accessors

base

  • get base(): string

Private config

  • get config(): Config

deps

  • get deps(): string[]

name

  • get name(): string

Methods

destroy

  • _destroy(): void

get

  • get<T>(path: string, type?: AssetType<T> | null): T | null
  • 通过路径与类型获取已缓存资源。在你使用 {{#crossLink "Bundle/load:method"}}{{/crossLink}} 或者 {{#crossLink "Bundle/loadDir:method"}}{{/crossLink}} 之后, 你能通过传路径通过这个 API 获取到这些资源。

    注意:传入的 path 与 type 参数需要与 Bundle.load 加载资源时传入的参数一致,否则可能会获取到其他同名资源

    example

    bundle1.get('music/hit', cc.AudioClip);

    Type parameters

    Parameters

    • path: string

      The path of asset

    • Optional type: AssetType<T> | null

      Only asset of type will be returned if this argument is supplied.

    Returns T | null

    • the asset has been cached

getAssetInfo

  • getAssetInfo(uuid: string): IAssetInfo | null
  • 通过 uuid 获取资源信息

    method

    getAssetInfo

    example

    var info = bundle.getAssetInfo('fcmR3XADNLgJ1ByKhqcC5Z');

    Parameters

    • uuid: string

      The asset's uuid

    Returns IAssetInfo | null

    info

getDirWithPath

  • getDirWithPath(path: string, type?: AssetType | null, out?: IAddressableInfo[]): IAddressableInfo[]
  • 获取在某个指定文件夹下的所有资源信息

    example

    var infos = []; bundle.getDirWithPath('images', cc.Texture2D, infos);

    Parameters

    • path: string

      The relative path of folder, such as 'images'

    • Optional type: AssetType | null

      The constructor should be used to filter paths

    • Optional out: IAddressableInfo[]

      The output array

    Returns IAddressableInfo[]

    Infos

getInfoWithPath

  • getInfoWithPath(path: string, type?: AssetType | null): IAddressableInfo | null
  • 使用 path 获取资源的配置信息

    example

    var info = bundle.getInfoWithPath('image/a', cc.Texture2D);

    Parameters

    • path: string

      The relative path of asset, such as 'images/a'

    • Optional type: AssetType | null

      The constructor of asset, such as cc.Texture2D

    Returns IAddressableInfo | null

    The asset info

getSceneInfo

  • getSceneInfo(name: string): ISceneInfo | null
  • 通过场景名获取场景信息

    method

    getSceneInfo

    example

    var info = bundle.getSceneInfo('first.fire');

    Parameters

    • name: string

      The name of scene

    Returns ISceneInfo | null

    info

init

  • init(options: IConfigOption): void

load

  • load<T>(paths: string, type: AssetType<T> | null, onProgress: ProgressCallback | null, onComplete: CompleteCallbackWithData<T> | null): void
  • load<T>(paths: string[], type: AssetType<T> | null, onProgress: ProgressCallback | null, onComplete: CompleteCallbackWithData<T[]> | null): void
  • load<T>(paths: string, onProgress: ProgressCallback | null, onComplete: CompleteCallbackWithData<T> | null): void
  • load<T>(paths: string[], onProgress: ProgressCallback | null, onComplete: CompleteCallbackWithData<T[]> | null): void
  • load<T>(paths: string, onComplete?: CompleteCallbackWithData<T> | null): void
  • load<T>(paths: string[], onComplete?: CompleteCallbackWithData<T[]> | null): void
  • load<T>(paths: string, type: AssetType<T> | null, onComplete?: CompleteCallbackWithData<T> | null): void
  • load<T>(paths: string[], type: AssetType<T> | null, onComplete?: CompleteCallbackWithData<T[]> | null): void
  • 通过相对路径加载分包中的资源。路径是相对分包文件夹路径的相对路径

    example

    // load the texture (${project}/assets/resources/textures/background.jpg) from resources cc.resources.load('textures/background', cc.Texture2D, (err, texture) => console.log(err)); // load the audio (${project}/assets/resources/music/hit.mp3) from resources cc.resources.load('music/hit', cc.AudioClip, (err, audio) => console.log(err)); // load the prefab (${project}/assets/bundle1/misc/character/cocos) from bundle1 folder bundle1.load('misc/character/cocos', cc.Prefab, (err, prefab) => console.log(err)); // load the sprite frame (${project}/assets/some/xxx/bundle2/imgs/cocos.png) from bundle2 folder bundle2.load('imgs/cocos', cc.SpriteFrame, null, (err, spriteFrame) => console.log(err));

    Type parameters

    Parameters

    • paths: string

      Paths of the target assets.The path is relative to the bundle's folder, extensions must be omitted.

    • type: AssetType<T> | null

      Only asset of type will be loaded if this argument is supplied.

    • onProgress: ProgressCallback | null

      Callback invoked when progression change.

    • onComplete: CompleteCallbackWithData<T> | null

      Callback invoked when all assets loaded.

    Returns void

  • Type parameters

    Parameters

    • paths: string[]
    • type: AssetType<T> | null
    • onProgress: ProgressCallback | null
    • onComplete: CompleteCallbackWithData<T[]> | null

    Returns void

  • Type parameters

    Parameters

    • paths: string
    • onProgress: ProgressCallback | null
    • onComplete: CompleteCallbackWithData<T> | null

    Returns void

  • Type parameters

    Parameters

    • paths: string[]
    • onProgress: ProgressCallback | null
    • onComplete: CompleteCallbackWithData<T[]> | null

    Returns void

  • Type parameters

    Parameters

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

    Returns void

  • Type parameters

    Parameters

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

    Returns void

  • Type parameters

    Parameters

    • paths: string
    • type: AssetType<T> | null
    • Optional onComplete: CompleteCallbackWithData<T> | null

    Returns void

  • Type parameters

    Parameters

    • paths: string[]
    • type: AssetType<T> | null
    • Optional onComplete: CompleteCallbackWithData<T[]> | null

    Returns void

loadDir

  • loadDir<T>(dir: string, type: AssetType<T> | null, onProgress: ProgressCallback | null, onComplete: CompleteCallbackWithData<T[]> | null): void
  • loadDir<T>(dir: string, onProgress: ProgressCallback | null, onComplete: CompleteCallbackWithData<T[]> | null): void
  • loadDir<T>(dir: string, onComplete?: CompleteCallbackWithData<T[]> | null): void
  • loadDir<T>(dir: string, type: AssetType<T> | null, onComplete?: CompleteCallbackWithData<T[]> | null): void
  • 加载目标文件夹中的所有资源, 注意:路径中只能使用斜杠,反斜杠将停止工作

    example

    // load all audios (resources/audios/) cc.resources.loadDir('audios', cc.AudioClip, (err, audios) => {}); // load all textures in "resources/imgs/" cc.resources.loadDir('imgs', cc.Texture2D, null, function (err, textures) { var texture1 = textures[0]; var texture2 = textures[1]; }); // load all prefabs (${project}/assets/bundle1/misc/characters/) from bundle1 folder bundle1.loadDir('misc/characters', cc.Prefab, (err, prefabs) => console.log(err)); // load all sprite frame (${project}/assets/some/xxx/bundle2/skills/) from bundle2 folder bundle2.loadDir('skills', cc.SpriteFrame, null, (err, spriteFrames) => console.log(err));

    Type parameters

    Parameters

    • dir: string

      path of the target folder.The path is relative to the bundle folder, extensions must be omitted.

    • type: AssetType<T> | null

      Only asset of type will be loaded if this argument is supplied.

    • onProgress: ProgressCallback | null

      Callback invoked when progression change.

    • onComplete: CompleteCallbackWithData<T[]> | null

      A callback which is called when all assets have been loaded, or an error occurs.

    Returns void

  • Type parameters

    Parameters

    • dir: string
    • onProgress: ProgressCallback | null
    • onComplete: CompleteCallbackWithData<T[]> | null

    Returns void

  • Type parameters

    Parameters

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

    Returns void

  • Type parameters

    Parameters

    • dir: string
    • type: AssetType<T> | null
    • Optional onComplete: CompleteCallbackWithData<T[]> | null

    Returns void

loadScene

  • loadScene(sceneName: string, options: IAssetOptions | null, onProgress: ProgressCallback | null, onComplete: CompleteCallbackWithData<SceneAsset> | null): void
  • loadScene(sceneName: string, onProgress: ProgressCallback | null, onComplete: CompleteCallbackWithData<SceneAsset> | null): void
  • loadScene(sceneName: string, options: IAssetOptions | null, onComplete?: CompleteCallbackWithData<SceneAsset> | null): void
  • loadScene(sceneName: string, onComplete?: CompleteCallbackWithData<SceneAsset> | null): void
  • 通过场景名称加载分包中的场景。

    example

    bundle1.loadScene('first', (err, sceneAsset) => cc.director.runScene(sceneAsset));

    Parameters

    • sceneName: string

      The name of the scene to load.

    • options: IAssetOptions | null

      Some optional parameters

    • onProgress: ProgressCallback | null

      Callback invoked when progression change.

    • onComplete: CompleteCallbackWithData<SceneAsset> | null

      callback, will be called after scene launched.

    Returns void

  • Parameters

    • sceneName: string
    • onProgress: ProgressCallback | null
    • onComplete: CompleteCallbackWithData<SceneAsset> | null

    Returns void

  • Parameters

    • sceneName: string
    • options: IAssetOptions | null
    • Optional onComplete: CompleteCallbackWithData<SceneAsset> | null

    Returns void

  • Parameters

    • sceneName: string
    • Optional onComplete: CompleteCallbackWithData<SceneAsset> | null

    Returns void

preload

  • preload(paths: string | string[], type: AssetType | null, onProgress: ProgressCallback | null, onComplete: CompleteCallbackWithData<RequestItem[]> | null): void
  • preload(paths: string | string[], onProgress: ProgressCallback | null, onComplete: CompleteCallbackWithData<RequestItem[]> | null): void
  • preload(paths: string | string[], onComplete?: CompleteCallbackWithData<RequestItem[]> | null): void
  • preload(paths: string | string[], type: AssetType | null, onComplete?: CompleteCallbackWithData<RequestItem[]> | null): void
  • 通过相对路径预加载分包中的资源。路径是相对分包文件夹路径的相对路径。调用完后,你仍然需要通过 Bundle.load 来完成加载。 就算预加载还没完成,你也可以直接调用 Bundle.load

    example

    // preload the texture (${project}/assets/resources/textures/background.jpg) from resources cc.resources.preload('textures/background', cc.Texture2D); // preload the audio (${project}/assets/resources/music/hit.mp3) from resources cc.resources.preload('music/hit', cc.AudioClip); // wait for while cc.resources.load('music/hit', cc.AudioClip, (err, audioClip) => {});

    • // preload the prefab (${project}/assets/bundle1/misc/character/cocos) from bundle1 folder bundle1.preload('misc/character/cocos', cc.Prefab); // load the sprite frame of (${project}/assets/bundle2/imgs/cocos.png) from bundle2 folder bundle2.preload('imgs/cocos', cc.SpriteFrame); // wait for while bundle2.load('imgs/cocos', cc.SpriteFrame, (err, spriteFrame) => {});

    Parameters

    • paths: string | string[]

      Paths of the target asset.The path is relative to bundle folder, extensions must be omitted.

    • type: AssetType | null

      Only asset of type will be loaded if this argument is supplied.

    • onProgress: ProgressCallback | null

      Callback invoked when progression change.

    • onComplete: CompleteCallbackWithData<RequestItem[]> | null

      Callback invoked when the resource loaded.

    Returns void

  • Parameters

    • paths: string | string[]
    • onProgress: ProgressCallback | null
    • onComplete: CompleteCallbackWithData<RequestItem[]> | null

    Returns void

  • Parameters

    • paths: string | string[]
    • Optional onComplete: CompleteCallbackWithData<RequestItem[]> | null

    Returns void

  • Parameters

    • paths: string | string[]
    • type: AssetType | null
    • Optional onComplete: CompleteCallbackWithData<RequestItem[]> | null

    Returns void

preloadDir

  • preloadDir(dir: string, type: AssetType | null, onProgress: ProgressCallback | null, onComplete: CompleteCallbackWithData<RequestItem[]> | null): void
  • preloadDir(dir: string, onProgress: ProgressCallback | null, onComplete: CompleteCallbackWithData<RequestItem[]> | null): void
  • preloadDir(dir: string, onComplete?: CompleteCallbackWithData<RequestItem[]> | null): void
  • preloadDir(dir: string, type: AssetType | null, onComplete?: CompleteCallbackWithData<RequestItem[]> | null): void
  • 预加载目标文件夹中的所有资源。调用完后,你仍然需要通过 Bundle.loadDir 来完成加载。 就算预加载还没完成,你也可以直接调用 Bundle.loadDir

    example

    // preload all audios (resources/audios/) cc.resources.preloadDir('audios', cc.AudioClip); // preload all textures in "resources/imgs/" cc.resources.preloadDir('imgs', cc.Texture2D); // wait for while cc.resources.loadDir('imgs', cc.Texture2D, (err, textures) => {}); // preload all prefabs (${project}/assets/bundle1/misc/characters/) from bundle1 folder bundle1.preloadDir('misc/characters', cc.Prefab); // preload all sprite frame (${project}/assets/some/xxx/bundle2/skills/) from bundle2 folder bundle2.preloadDir('skills', cc.SpriteFrame); // wait for while bundle2.loadDir('skills', cc.SpriteFrame, (err, spriteFrames) => {});

    Parameters

    • dir: string

      path of the target folder.The path is relative to the bundle folder, extensions must be omitted.

    • type: AssetType | null

      Only asset of type will be preloaded if this argument is supplied.

    • onProgress: ProgressCallback | null

      Callback invoked when progression change.

    • onComplete: CompleteCallbackWithData<RequestItem[]> | null

      A callback which is called when all assets have been loaded, or an error occurs.

    Returns void

  • Parameters

    • dir: string
    • onProgress: ProgressCallback | null
    • onComplete: CompleteCallbackWithData<RequestItem[]> | null

    Returns void

  • Parameters

    • dir: string
    • Optional onComplete: CompleteCallbackWithData<RequestItem[]> | null

    Returns void

  • Parameters

    • dir: string
    • type: AssetType | null
    • Optional onComplete: CompleteCallbackWithData<RequestItem[]> | null

    Returns void

preloadScene

  • preloadScene(sceneName: string, options: IAssetOptions | null, onProgress: ProgressCallback, onComplete: CompleteCallbackNoData | null): void
  • preloadScene(sceneName: string, onProgress: ProgressCallback | null, onComplete: CompleteCallbackNoData | null): void
  • preloadScene(sceneName: string, options: IAssetOptions | null, onComplete?: CompleteCallbackNoData | null): void
  • preloadScene(sceneName: string, onComplete?: CompleteCallbackNoData | null): void
  • 通过场景名称预加载分包中的场景.调用完后,你仍然需要通过 Bundle.loadScenecc.director.loadScene 来完成加载。 就算预加载还没完成,你也可以直接调用 Bundle.loadScenecc.director.loadScene

    example

    bundle1.preloadScene('first'); // wait for a while bundle1.loadScene('first', (err, scene) => cc.director.runScene(scene));

    Parameters

    • sceneName: string

      The name of the scene to preload.

    • options: IAssetOptions | null

      Some optional parameters

    • onProgress: ProgressCallback

      callback, will be called when the load progression change.

    • onComplete: CompleteCallbackNoData | null

      callback, will be called after scene loaded.

    Returns void

  • Parameters

    • sceneName: string
    • onProgress: ProgressCallback | null
    • onComplete: CompleteCallbackNoData | null

    Returns void

  • Parameters

    • sceneName: string
    • options: IAssetOptions | null
    • Optional onComplete: CompleteCallbackNoData | null

    Returns void

  • Parameters

    • sceneName: string
    • Optional onComplete: CompleteCallbackNoData | null

    Returns void

release

  • release(path: string, type?: AssetType | null): void
  • 释放通过 {{#crossLink "Bundle/load:method"}}{{/crossLink}} 或者 {{#crossLink "Bundle/loadDir:method"}}{{/crossLink}} 加载的资源。 详细信息请参考 {{#crossLink "AssetManager/releaseAsset:method"}}{{/crossLink}}

    注意:传入的 path 与 type 参数需要与 Bundle.load 加载资源时传入的参数一致,否则可能会释放到其他同名资源

    example

    // release a texture which is no longer need bundle1.release('misc/character/cocos');

    Parameters

    • path: string

      The path of asset

    • Optional type: AssetType | null

      Only asset of type will be released if this argument is supplied.

    Returns void

releaseAll

  • releaseAll(): void
  • 释放此包中的所有资源。详细信息请参考 {{#crossLink "AssetManager/releaseAll:method"}}{{/crossLink}}

    example

    // release all asset within bundle1 bundle1.releaseAll();

    Returns void

Private releaseUnusedAssets

  • releaseUnusedAssets(): void
  • 释放此包中的所有没有用到的资源。详细信息请参考 {{#crossLink "AssetManager/releaseAll:method"}}{{/crossLink}}

    example

    // release all unused asset within bundle1 bundle1.releaseUnusedAssets();

    Returns void

Generated using TypeDoc