# Class: ShapeInteract

拥有ShapeInterace组件的Shape才能与其他Shape发生交互。
将`collide`属性设置为true来与其他Shape进行物理碰撞，仅当两个Shape的collide属性**都为true**时它们才能发生碰撞。

## Hierarchy

- [`Component`](Component)

  ↳ **`ShapeInteract`**

## Table of contents

### Constructors

- constructor

### Events

- onAdd
- onRelease
- onRemove
- onTick
- onUpdate

### Properties

- priority
- schema
- EVENTS

### Accessors

- bounceCombine
- bounciness
- dynamicFriction
- el
- frictionCombine
- scene
- staticFriction
- version

### Methods

- getData
- getInteractType
- setData
- setDataOne

## Constructors

### constructor

• **new ShapeInteract**()

#### Overrides

[Component](Component).[constructor](Component#constructor)

## Events

### onAdd

▸ **onAdd**(`parent`, `data`): `void`

所挂载的`element`被挂载到场景时触发的回调。

#### Parameters

| Name | Type |
| :------ | :------ |
| `parent` | [`Element`](Element) |
| `data` | [`IShapeInteractData`](/miniprogram/dev/reference/xr-frame/api/interfaces/IShapeInteractData) |

#### Returns

`void`

#### Inherited from

[Component](Component).[onAdd](Component#onAdd)

___

### onRelease

▸ **onRelease**(`data`): `void`

从被挂载的`element`上被移除，或是`element`被销毁时，触发的回调。
一般用于释放持有的资源。

#### Parameters

| Name | Type |
| :------ | :------ |
| `data` | [`IShapeInteractData`](/miniprogram/dev/reference/xr-frame/api/interfaces/IShapeInteractData) |

#### Returns

`void`

#### Inherited from

[Component](Component).[onRelease](Component#onRelease)

___

### onRemove

▸ **onRemove**(`parent`, `data`): `void`

所挂载的`element`从父节点`parent`被移除时，或者自己从`element`上被移除时，触发的回调。
一般用于消除功能的运作。
**如果一个组件的元素直接被销毁了，那这个组件就不会经历onRemove而是直接进入onRelease。**

#### Parameters

| Name | Type |
| :------ | :------ |
| `parent` | [`Element`](Element) |
| `data` | [`IShapeInteractData`](/miniprogram/dev/reference/xr-frame/api/interfaces/IShapeInteractData) |

#### Returns

`void`

#### Inherited from

[Component](Component).[onRemove](Component#onRemove)

___

### onTick

▸ **onTick**(`deltaTime`, `data`): `void`

渲染每帧触发的回调。

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `deltaTime` | `number` | 单位为毫秒(ms)。 |
| `data` | [`IShapeInteractData`](/miniprogram/dev/reference/xr-frame/api/interfaces/IShapeInteractData) | - |

#### Returns

`void`

#### Inherited from

[Component](Component).[onTick](Component#onTick)

___

### onUpdate

▸ **onUpdate**(`data`, `preData`): `void`

数据更新时触发的回调。

#### Parameters

| Name | Type |
| :------ | :------ |
| `data` | [`IShapeInteractData`](/miniprogram/dev/reference/xr-frame/api/interfaces/IShapeInteractData) |
| `preData` | [`IShapeInteractData`](/miniprogram/dev/reference/xr-frame/api/interfaces/IShapeInteractData) |

#### Returns

`void`

#### Inherited from

[Component](Component).[onUpdate](Component#onUpdate)

## Properties

### priority

• `Readonly` **priority**: `number`

自定义组件的更新优先级。

#### Inherited from

[Component](Component).[priority](Component#priority)

___

### schema

• `Readonly` **schema**: [`IComponentSchema`](/miniprogram/dev/reference/xr-frame/api/interfaces/IComponentSchema)

自定义组件的`schema`。

#### Overrides

[Component](Component).[schema](Component#schema)

___

### EVENTS

▪ `Static` **EVENTS**: `string`[] = `[]`

#### Inherited from

[Component](Component).[EVENTS](Component#EVENTS)

## Accessors

### bounceCombine

• `get` **bounceCombine**(): `CombineMode`

如何结合发生碰撞的两个物体的弹性系数。

**`default`** {@link CombineMode.Average}

#### Returns

`CombineMode`

• `set` **bounceCombine**(`v`): `void`

如何结合发生碰撞的两个物体的弹性系数。

#### Parameters

| Name | Type |
| :------ | :------ |
| `v` | `CombineMode` |

#### Returns

`void`

___

### bounciness

• `get` **bounciness**(): `number`

弹性系数，决定碰撞时的能量损失比例。

弹性系数 = 1时，碰撞无能量损失。

**`limit`** 0 (`key`): [`IShapeInteractData`](/miniprogram/dev/reference/xr-frame/api/interfaces/IShapeInteractData)[`T`]

获取一个当前值。

#### Type parameters

| Name | Type |
| :------ | :------ |
| `T` | extends keyof [`IShapeInteractData`](/miniprogram/dev/reference/xr-frame/api/interfaces/IShapeInteractData) |

#### Parameters

| Name | Type |
| :------ | :------ |
| `key` | `T` |

#### Returns

[`IShapeInteractData`](/miniprogram/dev/reference/xr-frame/api/interfaces/IShapeInteractData)[`T`]

#### Inherited from

[Component](Component).[getData](Component#getData)

___

### getInteractType

▸ **getInteractType**(): `EShapeInteractType`

#### Returns

`EShapeInteractType`

___

### setData

▸ **setData**(`data`): `void`

不通过`xml`而是直接设置`data`，注意值的类型需要和`schema`中一致。

#### Parameters

| Name | Type |
| :------ | :------ |
| `data` | `Partial` |

#### Returns

`void`

#### Inherited from

[Component](Component).[setData](Component#setData)

___

### setDataOne

▸ **setDataOne**(`key`, `value`): `void`

设置一个数据。

#### Type parameters

| Name | Type |
| :------ | :------ |
| `T` | extends keyof [`IShapeInteractData`](/miniprogram/dev/reference/xr-frame/api/interfaces/IShapeInteractData) |

#### Parameters

| Name | Type |
| :------ | :------ |
| `key` | `T` |
| `value` | [`IShapeInteractData`](/miniprogram/dev/reference/xr-frame/api/interfaces/IShapeInteractData)[`T`] |

#### Returns

`void`

#### Inherited from

[Component](Component).[setDataOne](Component#setDataOne)
