> 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. 打开屏幕右上角的齿轮图标
2. 在 **首选代码编辑器**，选择你的代码编辑器。你可能会在下拉菜单中找到你的编辑器，或者你可能需要选择 **从你的设备中选择...** 来找到它。

## 打开场景代码

在你的机器上安装代码编辑器并在 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)

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

![](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)

在 `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 进行 Vibe Coding](/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 进行 Vibe Coding](/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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
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=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
