# Class: AssetLoader

资源加载器的基类，配合[AssetsSystem](AssetsSystem)使用。
在基础库版本**v2.29.2**以上导出。

## Type parameters

| Name | Description |
| :------ | :------ |
| `T` | 加载资源的类型。 |
| `ILoadOptions` | 可接受额外配置的类型。 |

## Hierarchy

- **`AssetLoader`**

  ↳ [`TextureLoader`](TextureLoader)

  ↳ [`ImageLoader`](ImageLoader)

  ↳ [`CubeTextureLoader`](CubeTextureLoader)

  ↳ [`VideoTextureLoader`](VideoTextureLoader)

  ↳ [`EnvDataLoader`](EnvDataLoader)

  ↳ [`GLTFLoader`](GlTFLoader)

  ↳ [`KeyframeLoader`](KeyframeLoader)

  ↳ [`RawLoader`](RawLoader)

  ↳ [`AtlasLoader`](AtlasLoader)

## Table of contents

### Constructors

- constructor

### Properties

- schema

### Accessors

- scene

### Methods

- cancel
- getBuiltin
- load
- release

## Constructors

### constructor

• **new AssetLoader**(`_scene`, `type`)

#### Type parameters

| Name |
| :------ |
| `T` |
| `ILoadOptions` |

#### Parameters

| Name | Type |
| :------ | :------ |
| `_scene` | [`Scene`](Scene) |
| `type` | `string` |

## Properties

### schema

• `Readonly` **schema**: [`ILoaderOptionsSchema`](/miniprogram/dev/reference/xr-frame/api/interfaces/ILoaderOptionsSchema) = `{}`

和[Component.schema](Component#schema)类似，指定解析Options的实际`schema`，对应于`ILoadOptions`。

## Accessors

### scene

• `get` **scene**(): [`Scene`](Scene)

当前资源所属场景的实例。

#### Returns

[`Scene`](Scene)

## Methods

### cancel

▸ **cancel**(`params`): `void`

取消加载特定资源。一般不需要自己编写逻辑，而是使用`entity.canceled`在加载终点丢弃。
注意`entity.canceled`是在这里赋值的，所以一般继承请务必先执行`super.cancel()`！

#### Parameters

| Name | Type |
| :------ | :------ |
| `params` | `IAssetLoadData` |

#### Returns

`void`

___

### getBuiltin

▸ **getBuiltin**(): { `assetId`: `string` ; `options`: `ILoadOptions` ; `src`: `string`  }[]

返回默认资源列表。
所有默认资源都是惰性加载的。

#### Returns

{ `assetId`: `string` ; `options`: `ILoadOptions` ; `src`: `string`  }[]

___

### load

▸ **load**(`data`, `callbacks`): `void`

加载一个资源，并根据情况执行`callbacks`中的回调。
**理论上必须要实现！**

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `data` | `IAssetLoadData` | - |
| `callbacks` | `Object` | 开发者需要在加载进度更新时执行`onLoading`，在加载完成时执行`onLoaded`，在加载出错是执行`onError` |
| `callbacks.onError` | (`error`: `Error`) => `void` | - |
| `callbacks.onLoaded` | (`result`: `T`, `localPath?`: `string`) => `void` | - |
| `callbacks.onLoading` | (`progress`: `number`) => `void` | - |

#### Returns

`void`

___

### release

▸ **release**(`params`, `value`): `void`

释放资源时将会调用，用于自定义释放逻辑。

#### Parameters

| Name | Type |
| :------ | :------ |
| `params` | `IAssetLoadData` |
| `value` | `T` |

#### Returns

`void`
