Skip to content
This repository has been archived by the owner on Aug 7, 2024. It is now read-only.

Commit

Permalink
update: script doc (#999)
Browse files Browse the repository at this point in the history
  • Loading branch information
MrKou47 authored Mar 20, 2024
1 parent f5fa378 commit ec23e04
Showing 1 changed file with 3 additions and 33 deletions.
36 changes: 3 additions & 33 deletions docs/script-create.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,39 +7,9 @@ label: Script

[脚本组件](${docs}script)是引擎提供给开发者的重要的扩展能力,在 Galacean 编辑器中,脚本也是一种资产。

```mermaid
flowchart LR
声明脚本 --> 绑定脚本
```
## 在编辑器中使用脚本

## 声明脚本
在编辑器中使用脚本非常方便,只需要创建脚本后,在实体的脚本组件中添加脚本即可。

[脚本类](${docs}script-class)中,我们已经了解了自定义脚本的基类 [Script](${api}core/Script) ,因此,我们可以使用如下代码声明自定义脚本:

```typescript
import { Script } from "@galacean/engine";

// 声明自定义脚本
class MyScript extends Script {
onUpdate() {}
}
```

在编辑器中可通过 `资源面板` 右上角点击 `+` 按钮,在弹出的菜单中点击 `脚本` 来声明自定义脚本:
![image-20210720204826392](https://mdn.alipayobjects.com/huamei_vrnqmp/afts/img/A*yl9gR7Jm1s8AAAAAAAAAAAAADgeMAQ/original)

## 绑定脚本

声明脚本后,需要将其绑定到节点上才能运行:

1. 选择你想添加脚本的实体
![image-20210720205530946](https://mdn.alipayobjects.com/huamei_vrnqmp/afts/img/A*xpU9S4BPYIUAAAAAAAAAAAAADgeMAQ/original)

2. 在右侧的组件列表中点击 `添加组件` -> 脚本 -> 选择你之前创建的脚本
![image-20210720210619665](https://mdn.alipayobjects.com/huamei_vrnqmp/afts/img/A*FcveToRFlmQAAAAAAAAAAAAADgeMAQ/original)

您也可以通过如下代码为实体绑定脚本:

```typescript
entity.addComponent(MyScript);
```
![Script](https://mdn.alipayobjects.com/huamei_fvsq9p/afts/img/A*Qw0rTbQPyWYAAAAAAAAAAAAADqiTAQ/original)

0 comments on commit ec23e04

Please sign in to comment.