> 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). Agents can also search and read this documentation through its [MCP server](https://docs.decentraland.org/~gitbook/mcp).

# 与代码结合

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

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

Creator Hub 与自定义代码的结合非常强大，可用于创建内容。你可以在画布上直观地摆放项目，然后自由编写与这些项目交互的代码。你甚至可以放置一个智能项目，它自带默认行为，并编写代码来响应该项目被激活的情况。

例如，你可以利用现有的杠杆智能项目，它已经包含音效、动画和状态，然后编写代码来检测杠杆何时被拉动，并运行你自己的自定义逻辑。

请参阅 [在代码中引用项目](https://docs.decentraland.org/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-38ec445a6fa4d8c8b4e5f5c7b80ea1e58b35b6df%2Fvscode.webp?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-96c78b13a696e8a70912e19e76551a23ec486a5b%2Fcursor-icon.webp?alt=media" alt="Cursor" data-size="line"> [Cursor AI](https://www.cursor.com/)：这是一款集成了 AI 的强大代码编辑器。你可以选择不同的 AI 模型来协助编写代码；它提供免费套餐，更高级的模型则需要付费方案。对于刚接触 Decentraland 或 TypeScript 的开发者，或者希望节省编写代码时间的开发者来说，这是一个不错的选择。

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

安装完成后，你可能需要在 Creator Hub 设置中选择代码编辑器。操作方法如下：

1. 点击屏幕左上角的 Creator Hub 徽标，然后选择 **设置**.
2. 打开 **编辑器** 选项卡。
3. 在 **首选代码编辑器**下，选择你的代码编辑器。你可能会在下拉列表中找到编辑器，也可以选择 **从设备中选择...** 来查找。

![“应用偏好设置”对话框中的“编辑器”选项卡，显示“首选代码编辑器”下拉菜单已设为 Visual Studio Code。](https://2460066822-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoPnXBby9S6MrsW83Y9qZ%2Fuploads%2Fgit-blob-f029dfd5bb1c2065716584e240489cba215873d8%2Fsettings-editor.webp?alt=media)

## 打开场景代码

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

![](https://2460066822-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoPnXBby9S6MrsW83Y9qZ%2Fuploads%2Fgit-blob-533a4b014b14355abfb053041727f76f80af1bf0%2Fcode-button.webp?alt=media)

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

![](https://2460066822-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoPnXBby9S6MrsW83Y9qZ%2Fuploads%2Fgit-blob-8edff2d8b3628c0a40ddc86186b306e09d36923a%2Ffiles-on-vs-studio.webp?alt=media)

在 `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 助手](https://docs.decentraland.org/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 进行氛围式编程](https://docs.decentraland.org/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 进行氛围式编程](https://docs.decentraland.org/creator/content-creator-zh/chang-jing-sdk7/ru-men/vibe-coding.md)：向 AI 助手描述你的需求，即可构建场景。
* [智能项目 - 基础](https://docs.decentraland.org/creator/content-creator-zh/chang-jing-bian-ji-qi/jiao-hu-xing/smart-items.md)
* [智能项目 - 进阶](https://docs.decentraland.org/creator/content-creator-zh/chang-jing-bian-ji-qi/jiao-hu-xing/smart-items-advanced.md)
* [状态与条件](https://docs.decentraland.org/creator/content-creator-zh/chang-jing-bian-ji-qi/jiao-hu-xing/states-and-conditions.md)
* [让任何项目变得智能](https://docs.decentraland.org/creator/content-creator-zh/chang-jing-bian-ji-qi/jiao-hu-xing/make-any-item-smart.md)
* [SDK 快速入门](https://docs.decentraland.org/creator/content-creator-zh/chang-jing-sdk7/ru-men/sdk-101.md)：跟随本迷你教程，快速了解基础知识。
* [开发工作流](https://docs.decentraland.org/creator/content-creator-zh/chang-jing-sdk7/ru-men/dev-workflow.md)：阅读本文，了解从头到尾创建场景的完整流程。
* [示例](https://docs.decentraland.org/creator/content-creator-zh/jiao-cheng-yu-shi-li/examples.md)：直接开始使用可运行的示例场景。


---

# 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.
