> For the complete documentation index, see [llms.txt](https://docs.decentraland.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.decentraland.org/creator/content-creator-zh/chang-jing-bian-ji-qi/shi-yong-dai-ma-kuo-zhan/overview.md).

# 与代码结合

将 Scene Editor 中创建的内容与代码编写的能力结合起来。

{% embed url="<https://www.youtube.com/watch?v=55H37rygD7M>" %}

Creator Hub 加上自定义代码，是用于创建内容的非常强大的组合。你可以使用画布直观地可视化摆放项目，然后编写与这些项目交互的代码，完全自由。你甚至可以放置一个智能物品，它有自己的默认行为，并编写在该物品被激活时作出响应的代码。

例如，你可以利用现有的杠杆智能物品，它本身就带有声音、动画和状态，然后编写代码来检测杠杆何时被拉动，从而运行你自己的自定义逻辑。

参见 [在代码中引用物品](/creator/content-creator-zh/chang-jing-bian-ji-qi/shi-yong-dai-ma-kuo-zhan/reference-items.md) 了解如何在代码中按名称或按标签获取物品。

## 编辑代码

你必须在你的机器上安装一个代码编辑器，才能编辑场景代码。推荐的选项有：

* <img src="https://2460066822-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoPnXBby9S6MrsW83Y9qZ%2Fuploads%2Fgit-blob-72733d889cecbb74400d2c9292b43a212b253969%2Fvscode.png?alt=media" alt="VS Code" data-size="line"> [Visual Studio Code](https://code.visualstudio.com/)：这是推荐给有经验开发者的选项。
* <img src="https://2460066822-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoPnXBby9S6MrsW83Y9qZ%2Fuploads%2Fgit-blob-2c1650edc9dbc881f65cd788d7c8ccfa2c27575c%2Fcursor-icon.png?alt=media" alt="Cursor" data-size="line"> [Cursor AI](https://www.cursor.com/)：这是一个与 AI 集成的强大代码编辑器。它允许你选择不同的 AI 模型来帮助你写代码；提供免费层级，更高级的模型需要付费方案。对于刚接触 Decentraland 或 TypeScript 的开发者来说，这是一个不错的选择，或者当你想节省编写代码的时间时也很合适。

{% hint style="warning" %}
**📔 注意**：如果你使用的是 macOS，请确保代码编辑器应用位于 Applications 目录中。
{% endhint %}

安装完成后，你可能需要在 Creator Hub 的设置中选择你的代码编辑器。为此，

1. 点击屏幕左上角的 Creator Hub 标志并选择 **设置**.
2. 打开 **EDITOR** 选项卡中。
3. 在 **首选代码编辑器**，选择你的代码编辑器。你可能会在下拉菜单中找到你的编辑器，或者你可能需要选择 **从你的设备中选择...** 来找到它。

![EDITOR 选项卡上的应用偏好设置对话框，显示“首选代码编辑器”下拉菜单设置为 Visual Studio Code。](https://2460066822-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoPnXBby9S6MrsW83Y9qZ%2Fuploads%2Fgit-blob-8eacb18c746acee4ccd8f3caf2740c9f4f40c5a4%2Fsettings-editor.png?alt=media\&token=aa0f0526-13f4-44f0-87be-88fb70c529f4)

## 打开场景代码

在你的机器上安装代码编辑器，并在 Creator Hub 的设置中选择它之后，你就可以点击 **< > 代码** 按钮，在你的场景项目中打开它。

![](https://2460066822-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoPnXBby9S6MrsW83Y9qZ%2Fuploads%2Fgit-blob-5837e60ee5b65bd46815c97282d53b1a44a70665%2Fcode-button.png?alt=media\&token=bb2a8cec-e8bd-485a-bbe1-f402ceb2aebd)

这会打开一个单独的代码编辑器窗口。在左侧边栏中，你可以浏览项目的文件和文件夹结构。

![](https://2460066822-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoPnXBby9S6MrsW83Y9qZ%2Fuploads%2Fgit-blob-e94bcfd7f720dddb6343bbb79d444afae3cbff33%2Ffiles-on-vs-studio.png?alt=media\&token=7fd7a16b-31d1-434d-ae25-d9f82c65a66f)

将你的自定义代码添加到 `index.ts` 位于以下路径下的一个文件： `/src`，在 `main()` 函数中。否则，你也可以在该函数外添加自定义代码，或者创建新的 `.ts` 位于 `/src` 文件夹中的文件，但这些文件必须以某种方式在 `main()` 的函数中被引用 `index.ts`.

{% hint style="warning" %}
**📔 注意**：如果你已安装 VS Code 或 Cursor，但 **CODE** 按钮无法打开它，可能是因为你的机器上 VS Code 没有正确配置为通过命令行打开。大多数情况下，这会在默认安装时自动处理；但如果没有，请参阅 [来自 VS](https://code.visualstudio.com/docs/setup/mac#_launching-from-the-command-line) 的这些说明，以从命令行启用 VS Code。
{% endhint %}

如果你打开了一个预览窗口来运行你的场景，那么当你更改文件中的代码并保存时，场景会自动重新加载并应用你的更改。

## 使用 AI

Creator Hub 内置了 [AI 助手](/creator/content-creator-zh/chang-jing-bian-ji-qi/shi-yong-dai-ma-kuo-zhan/ai-assistant.md) 一个能看到你打开的场景并为你进行编辑的功能，而且无需离开应用。这是一项实验性功能，默认关闭。

你也可以借助 Cursor 或 Claude Code 等 AI 助手来帮助你编写场景代码。例如，要使用 Cursor，请这样做：

1. 通过点击 **AI** 按钮来打开 Cursor AI 助手，位于屏幕右上角
2. 在那里，你可以向 AI 助手发出提示，帮助你编写代码。你的提示可以包含文档页面链接、项目中特定文件的路径，甚至图片。你还可以从下拉菜单中选择要使用的特定模型。

为了让你的 AI 助手获得 Decentraland 上下文，请安装官方 Decentraland SDK Skills。这些是由 Decentraland 基金会维护的现成指令集，它们会为你的 AI 代理讲解经过验证的 SDK7 模式，涵盖每个主题：搭建整个场景、添加 3D 模型、多玩家、部署等等。

```bash
npx skills add decentraland/sdk-skills
```

参见 [借助 AI 进行氛围编程](/creator/content-creator-zh/chang-jing-sdk7/ru-men/vibe-coding.md) 以获取完整指南，包括可用技能的完整列表。

{% hint style="warning" %}
**📔 注意**：较旧的场景项目可能包含一个 `/dclcontext` 文件夹，由已弃用的 `npx sdk-commands get-context-files` 命令下载而来。该上下文已不再维护，并已被 SDK Skills 取代。你可以安全地删除该文件夹。
{% endhint %}

## 版本控制

我们建议你在 GitHub 上为你的项目创建一个仓库，并用它来跟踪项目版本以及与他人协作。

如果你不熟悉如何操作，请参阅 [仓库快速入门](https://docs.github.com/en/repositories/creating-and-managing-repositories/quickstart-for-repositories)，或者使用 [GitHub 桌面应用程序](https://desktop.github.com/download/) 以获得更简单的基于界面的流程。

{% hint style="warning" %}
**📔 注意**：将整个项目文件夹上传到 GitHub 仓库，但请确保 `/node_modules` 或 `/bin` 文件夹以及 `package-lock.json` 文件都包含在 `.gitignore` 文件中，以避免同步它们。如果你将仓库配置为类型为 `node`，则应当如此。这些文件都是自动生成的，内容可能因机器而异。
{% endhint %}

## 另请参阅

* [借助 AI 进行氛围编程](/creator/content-creator-zh/chang-jing-sdk7/ru-men/vibe-coding.md)：通过向 AI 助手描述你的需求来构建场景。
* [智能项目 - 基础](/creator/content-creator-zh/chang-jing-bian-ji-qi/jiao-hu-xing/smart-items.md)
* [智能物件 - 高级](/creator/content-creator-zh/chang-jing-bian-ji-qi/jiao-hu-xing/smart-items-advanced.md)
* [状态和条件](/creator/content-creator-zh/chang-jing-bian-ji-qi/jiao-hu-xing/states-and-conditions.md)
* [让任意项目变为智能项目](/creator/content-creator-zh/chang-jing-bian-ji-qi/jiao-hu-xing/make-any-item-smart.md)
* [SDK 快速入门](/creator/content-creator-zh/chang-jing-sdk7/ru-men/sdk-101.md)：跟随这个迷你教程快速入门。
* [开发工作流](/creator/content-creator-zh/chang-jing-sdk7/ru-men/dev-workflow.md)：阅读此内容以全面了解场景创建流程。
* [示例](https://studios.decentraland.org/resources?sdk_version=SDK7)：直接深入查看可运行的示例场景。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.decentraland.org/creator/content-creator-zh/chang-jing-bian-ji-qi/shi-yong-dai-ma-kuo-zhan/overview.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
