# Class ResLoader

游戏资管理 1、加载默认resources文件夹中资源 2、加载默认bundle远程资源 3、主动传递bundle名时，优先加载传递bundle名资源包中的资源

#### Hierarchy

- ResLoader

- Defined in assets/core/common/loader/ResLoader.ts:23

#####
Index

### Constructors

constructor

### Properties

defaultBundleName

### Methods

dump
get
load
loadAsync
loadBundle
loadByArgs
loadByBundleAndArgs
loadDir
loadRemote
parseLoadResArgs
release
releaseDir
releasePrefabtDepsRecursively

## Constructors

### constructor

- new ResLoader(): ResLoader

- #### Returns ResLoader

## Properties

### defaultBundleName

defaultBundleName: string = "resources"

全局默认加载的资源包名

- Defined in assets/core/common/loader/ResLoader.ts:25

## Methods

### dump

- dump(): void

- 打印缓存中所有资源信息

  #### Returns void

  - Defined in assets/core/common/loader/ResLoader.ts:265

### get

- get<T>(path: string, type?: null | __types_globals__Constructor<T>, bundleName?: string): null | T

- 获取资源

  #### Type Parameters

  - #### T extends Asset<T>

  #### Parameters

  - ##### path: string

    资源路径

  - ##### `Optional` type: null | __types_globals__Constructor<T>

    资源类型

  - ##### `Optional` bundleName: string

    远程资源包名

  #### Returns null | T

  - Defined in assets/core/common/loader/ResLoader.ts:257

### load

- load<T>(bundleName: string, paths: string | string[], type: null | AssetType <T>, onProgress: null | _cocos_asset_asset_manager_deprecated__LoadProgressCallback, onComplete: any): void

- 加载一个资源

  ### Example

      oops.res.load("spine_path", sp.SkeletonData, (err: Error | null, sd: sp.SkeletonData) => {

      });

  #### Type Parameters

  - #### T extends Asset<T>

  #### Parameters

  - ##### bundleName: string

    远程包名

  - ##### paths: string | string[]

    资源路径

  - ##### type: null | AssetType <T>

    资源类型

  - ##### onProgress: null | _cocos_asset_asset_manager_deprecated__LoadProgressCallback

    加载进度回调

  - ##### onComplete: any

    加载完成回调

  #### Returns void

  - Defined in assets/core/common/loader/ResLoader.ts:94
- load<T>(bundleName: string, paths: string | string[], onProgress: null | _cocos_asset_asset_manager_deprecated__LoadProgressCallback, onComplete: any): void

- #### Type Parameters

  - #### T extends Asset<T>

  #### Parameters

  - ##### bundleName: string

  - ##### paths: string | string[]

  - ##### onProgress: null | _cocos_asset_asset_manager_deprecated__LoadProgressCallback

  - ##### onComplete: any

  #### Returns void

  - Defined in assets/core/common/loader/ResLoader.ts:95
- load<T>(bundleName: string, paths: string | string[], onComplete?: any): void

- #### Type Parameters

  - #### T extends Asset<T>

  #### Parameters

  - ##### bundleName: string

  - ##### paths: string | string[]

  - ##### `Optional` onComplete: any

  #### Returns void

  - Defined in assets/core/common/loader/ResLoader.ts:96
- load<T>(bundleName: string, paths: string | string[], type: null | AssetType <T>, onComplete?: any): void

- #### Type Parameters

  - #### T extends Asset<T>

  #### Parameters

  - ##### bundleName: string

  - ##### paths: string | string[]

  - ##### type: null | AssetType <T>

  - ##### `Optional` onComplete: any

  #### Returns void

  - Defined in assets/core/common/loader/ResLoader.ts:97
- load<T>(paths: string | string[], type: null | AssetType <T>, onProgress: null | _cocos_asset_asset_manager_deprecated__LoadProgressCallback, onComplete: any): void

- #### Type Parameters

  - #### T extends Asset<T>

  #### Parameters

  - ##### paths: string | string[]

  - ##### type: null | AssetType <T>

  - ##### onProgress: null | _cocos_asset_asset_manager_deprecated__LoadProgressCallback

  - ##### onComplete: any

  #### Returns void

  - Defined in assets/core/common/loader/ResLoader.ts:98
- load<T>(paths: string | string[], onProgress: null | _cocos_asset_asset_manager_deprecated__LoadProgressCallback, onComplete: any): void

- #### Type Parameters

  - #### T extends Asset<T>

  #### Parameters

  - ##### paths: string | string[]

  - ##### onProgress: null | _cocos_asset_asset_manager_deprecated__LoadProgressCallback

  - ##### onComplete: any

  #### Returns void

  - Defined in assets/core/common/loader/ResLoader.ts:99
- load<T>(paths: string | string[], onComplete?: any): void

- #### Type Parameters

  - #### T extends Asset<T>

  #### Parameters

  - ##### paths: string | string[]

  - ##### `Optional` onComplete: any

  #### Returns void

  - Defined in assets/core/common/loader/ResLoader.ts:100
- load<T>(paths: string | string[], type: null | AssetType <T>, onComplete?: any): void

- #### Type Parameters

  - #### T extends Asset<T>

  #### Parameters

  - ##### paths: string | string[]

  - ##### type: null | AssetType <T>

  - ##### `Optional` onComplete: any

  #### Returns void

  - Defined in assets/core/common/loader/ResLoader.ts:101

### loadAsync

- loadAsync<T>(bundleName: string, paths: string | string[], type: null | AssetType <T>): Promise<T>

- #### Type Parameters

  - #### T extends Asset<T>

  #### Parameters

  - ##### bundleName: string

  - ##### paths: string | string[]

  - ##### type: null | AssetType <T>

  #### Returns Promise<T>

  - Defined in assets/core/common/loader/ResLoader.ts:121
- loadAsync<T>(bundleName: string, paths: string | string[]): Promise<T>

- #### Type Parameters

  - #### T extends Asset<T>

  #### Parameters

  - ##### bundleName: string

  - ##### paths: string | string[]

  #### Returns Promise<T>

  - Defined in assets/core/common/loader/ResLoader.ts:122
- loadAsync<T>(bundleName: string, paths: string | string[]): Promise<T>

- #### Type Parameters

  - #### T extends Asset<T>

  #### Parameters

  - ##### bundleName: string

  - ##### paths: string | string[]

  #### Returns Promise<T>

  - Defined in assets/core/common/loader/ResLoader.ts:123
- loadAsync<T>(bundleName: string, paths: string | string[], type: null | AssetType <T>): Promise<T>

- #### Type Parameters

  - #### T extends Asset<T>

  #### Parameters

  - ##### bundleName: string

  - ##### paths: string | string[]

  - ##### type: null | AssetType <T>

  #### Returns Promise<T>

  - Defined in assets/core/common/loader/ResLoader.ts:124
- loadAsync<T>(paths: string | string[], type: null | AssetType <T>): Promise<T>

- #### Type Parameters

  - #### T extends Asset<T>

  #### Parameters

  - ##### paths: string | string[]

  - ##### type: null | AssetType <T>

  #### Returns Promise<T>

  - Defined in assets/core/common/loader/ResLoader.ts:125
- loadAsync<T>(paths: string | string[]): Promise<T>

- #### Type Parameters

  - #### T extends Asset<T>

  #### Parameters

  - ##### paths: string | string[]

  #### Returns Promise<T>

  - Defined in assets/core/common/loader/ResLoader.ts:126
- loadAsync<T>(paths: string | string[]): Promise<T>

- #### Type Parameters

  - #### T extends Asset<T>

  #### Parameters

  - ##### paths: string | string[]

  #### Returns Promise<T>

  - Defined in assets/core/common/loader/ResLoader.ts:127
- loadAsync<T>(paths: string | string[], type: null | AssetType <T>): Promise<T>

- #### Type Parameters

  - #### T extends Asset<T>

  #### Parameters

  - ##### paths: string | string[]

  - ##### type: null | AssetType <T>

  #### Returns Promise<T>

  - Defined in assets/core/common/loader/ResLoader.ts:128

### loadBundle

- loadBundle(url: string, v?: string): Promise<Bundle>

- 加载资源包

  ### Example

      var serverUrl = "http://192.168.1.8:8080/";         // 服务器地址
      var md5 = "8e5c0";                                  // Cocos Creator 构建后的MD5字符
      await oops.res.loadBundle(serverUrl,md5);

  #### Parameters

  - ##### url: string

    资源地址

  - ##### `Optional` v: string

    资源MD5版本号

  #### Returns Promise<Bundle>

  - Defined in assets/core/common/loader/ResLoader.ts:71

### `Private` loadByArgs

- loadByArgs<T>(args: ILoadResArgs<T>): void

- #### Type Parameters

  - #### T extends Asset<T>

  #### Parameters

  - ##### args: ILoadResArgs<T>

  #### Returns void

  - Defined in assets/core/common/loader/ResLoader.ts:317

### `Private` loadByBundleAndArgs

- loadByBundleAndArgs<T>(bundle: Bundle, args: ILoadResArgs<T>): void

- #### Type Parameters

  - #### T extends Asset<T>

  #### Parameters

  - ##### bundle: Bundle

  - ##### args: ILoadResArgs<T>

  #### Returns void

  - Defined in assets/core/common/loader/ResLoader.ts:303

### loadDir

- loadDir<T>(bundleName: string, dir: string, type: null | AssetType <T>, onProgress: null | _cocos_asset_asset_manager_deprecated__LoadProgressCallback, onComplete: any): void

- 加载文件夹中的资源

  ### Example

      // 加载进度事件
      var onProgressCallback = (finished: number, total: number, item: any) => {
      console.log("资源加载进度", finished, total);
      }

      // 加载完成事件
      var onCompleteCallback = () => {
      console.log("资源加载完成");
      }
      oops.res.loadDir("game", onProgressCallback, onCompleteCallback);

  #### Type Parameters

  - #### T extends Asset<T>

  #### Parameters

  - ##### bundleName: string

    远程包名

  - ##### dir: string

    文件夹名

  - ##### type: null | AssetType <T>

    资源类型

  - ##### onProgress: null | _cocos_asset_asset_manager_deprecated__LoadProgressCallback

    加载进度回调

  - ##### onComplete: any

    加载完成回调

  #### Returns void

  - Defined in assets/core/common/loader/ResLoader.ts:159
- loadDir<T>(bundleName: string, dir: string, onProgress: null | _cocos_asset_asset_manager_deprecated__LoadProgressCallback, onComplete: any): void

- #### Type Parameters

  - #### T extends Asset<T>

  #### Parameters

  - ##### bundleName: string

  - ##### dir: string

  - ##### onProgress: null | _cocos_asset_asset_manager_deprecated__LoadProgressCallback

  - ##### onComplete: any

  #### Returns void

  - Defined in assets/core/common/loader/ResLoader.ts:160
- loadDir<T>(bundleName: string, dir: string, onComplete?: any): void

- #### Type Parameters

  - #### T extends Asset<T>

  #### Parameters

  - ##### bundleName: string

  - ##### dir: string

  - ##### `Optional` onComplete: any

  #### Returns void

  - Defined in assets/core/common/loader/ResLoader.ts:161
- loadDir<T>(bundleName: string, dir: string, type: null | AssetType <T>, onComplete?: any): void

- #### Type Parameters

  - #### T extends Asset<T>

  #### Parameters

  - ##### bundleName: string

  - ##### dir: string

  - ##### type: null | AssetType <T>

  - ##### `Optional` onComplete: any

  #### Returns void

  - Defined in assets/core/common/loader/ResLoader.ts:162
- loadDir<T>(dir: string, type: null | AssetType <T>, onProgress: null | _cocos_asset_asset_manager_deprecated__LoadProgressCallback, onComplete: any): void

- #### Type Parameters

  - #### T extends Asset<T>

  #### Parameters

  - ##### dir: string

  - ##### type: null | AssetType <T>

  - ##### onProgress: null | _cocos_asset_asset_manager_deprecated__LoadProgressCallback

  - ##### onComplete: any

  #### Returns void

  - Defined in assets/core/common/loader/ResLoader.ts:163
- loadDir<T>(dir: string, onProgress: null | _cocos_asset_asset_manager_deprecated__LoadProgressCallback, onComplete: any): void

- #### Type Parameters

  - #### T extends Asset<T>

  #### Parameters

  - ##### dir: string

  - ##### onProgress: null | _cocos_asset_asset_manager_deprecated__LoadProgressCallback

  - ##### onComplete: any

  #### Returns void

  - Defined in assets/core/common/loader/ResLoader.ts:164
- loadDir<T>(dir: string, onComplete?: any): void

- #### Type Parameters

  - #### T extends Asset<T>

  #### Parameters

  - ##### dir: string

  - ##### `Optional` onComplete: any

  #### Returns void

  - Defined in assets/core/common/loader/ResLoader.ts:165
- loadDir<T>(dir: string, type: null | AssetType <T>, onComplete?: any): void

- #### Type Parameters

  - #### T extends Asset<T>

  #### Parameters

  - ##### dir: string

  - ##### type: null | AssetType <T>

  - ##### `Optional` onComplete: any

  #### Returns void

  - Defined in assets/core/common/loader/ResLoader.ts:166

### loadRemote

- loadRemote<T>(url: string, options: IRemoteOptions, onComplete?: any): void

- 加载远程资源

  ### Example

      var opt: IRemoteOptions = { ext: ".png" };
      var onComplete = (err: Error | null, data: ImageAsset) => {
      const texture = new Texture2D();
      texture.image = data;

      const spriteFrame = new SpriteFrame();
      spriteFrame.texture = texture;

      var sprite = this.sprite.addComponent(Sprite);
      sprite.spriteFrame = spriteFrame;
      }
      oops.res.loadRemote<ImageAsset>(this.url, opt, onComplete);

  #### Type Parameters

  - #### T extends Asset<T>

  #### Parameters

  - ##### url: string

    资源地址

  - ##### options: IRemoteOptions

    资源参数，例：{ ext: ".png" }

  - ##### `Optional` onComplete: any

    加载完成回调

  #### Returns void

  - Defined in assets/core/common/loader/ResLoader.ts:46
- loadRemote<T>(url: string, onComplete?: any): void

- #### Type Parameters

  - #### T extends Asset<T>

  #### Parameters

  - ##### url: string

  - ##### `Optional` onComplete: any

  #### Returns void

  - Defined in assets/core/common/loader/ResLoader.ts:47

### `Private` parseLoadResArgs

- parseLoadResArgs<T>(paths: string | string[], type?: any, onProgress?: any, onComplete?: any): {
  onComplete: any;
  onProgress: any;
  paths: any;
  type: any;
  }

- #### Type Parameters

  - #### T extends Asset<T>

  #### Parameters

  - ##### paths: string | string[]

  - ##### `Optional` type: any

  - ##### `Optional` onProgress: any

  - ##### `Optional` onComplete: any

  #### Returns {
  onComplete: any;
  onProgress: any;
  paths: any;
  type: any;
  }

  - ##### onComplete: any

  - ##### onProgress: any

  - ##### paths: any

  - ##### type: any

  - Defined in assets/core/common/loader/ResLoader.ts:272

### release

- release(path: string, bundleName?: string): void

- 通过资源相对路径释放资源

  #### Parameters

  - ##### path: string

    资源路径

  - ##### `Optional` bundleName: string

    远程资源包名

  #### Returns void

  - Defined in assets/core/common/loader/ResLoader.ts:192

### releaseDir

- releaseDir(path: string, bundleName?: string): void

- 通过相对文件夹路径删除所有文件夹中资源

  #### Parameters

  - ##### path: string

    资源文件夹路径

  - ##### `Optional` bundleName: string

    远程资源包名

  #### Returns void

  - Defined in assets/core/common/loader/ResLoader.ts:209

### `Private` releasePrefabtDepsRecursively

- releasePrefabtDepsRecursively(uuid: string | Asset): void

- 释放预制依赖资源

  #### Parameters

  - ##### uuid: string | Asset

  #### Returns void

  - Defined in assets/core/common/loader/ResLoader.ts:228

Generated using TypeDoc