> For the complete documentation index, see [llms.txt](https://docs.convai.com/api-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/unity-plugin/building-for-supported-platforms/convai-xr/building-for-ar.md).

# 为 AR 构建

## AR 安装

如果你想让你的 Convai 插件兼容 AR，可以通过两种方式实现。请查看下面的说明，或者看看我们的 [*最新教程视频*](https://www.youtube.com/watch?v=j0l_paOQxvI) 在 YouTube 上。

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

### 方法 1：自动设置

{% hint style="success" %}
推荐用于新项目。
{% endhint %}

{% hint style="danger" %}
将执行以下过程：

* 通用渲染管线（URP）
* ARCore 插件
* Convai 自定义 AR 包
* Convai URP 转换器

**如果这些包不存在，将会安装它们。**
{% endhint %}

{% hint style="danger" %}
**如果目标构建平台不是 Android，将切换为&#x20;*****Android。***
{% endhint %}

{% hint style="warning" %}
请确保已从 Unity Hub 下载与你项目版本对应的 Android 平台支持。
{% endhint %}

1. 点击“ *Convai / Convai Custom Package Installer / 安装 AR 包* "

<figure><img src="/files/bd5a8cb37b5a569993e5d26835fff0cebd24e7c2" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/70e89a5d97387e8ffbf7822def3f85b4dd049ea3" alt=""><figcaption></figcaption></figure>

2. 确认将要进行的更改和操作。如果你同意，流程将开始。点击“ **是，继续** ”，流程将开始。你会在控制台中看到日志。

<figure><img src="/files/28676a12e21608368e08436c19a486c571314bf6" alt=""><figcaption></figcaption></figure>

3. 如果你遇到类似“Failed to Resolve Packages”的错误，不要担心。流程会继续，包安装完成后该错误会自动解决。

<figure><img src="/files/1eaad048b2f8805b8001ecfbf96e4c33d757cbfc" alt=""><figcaption></figcaption></figure>

4. 打开“ *Convai / Scenes / Convai Demo - AR* ”演示场景。如果出现 TMP 导入器窗口（如果你的项目中未安装 TMP Essentials，就会出现），点击“ **导入 TMP Essentials** ”以安装用于 UI 文本对象的 TextMeshPro Essentials。

<figure><img src="/files/641890529b0394cd48ede9bc1f464e4e5c44b1f4" alt=""><figcaption></figcaption></figure>

或者，你可以使用“ *Window / TextMeshPro / 导入 TMP 基础资源* ”来安装它。

<figure><img src="/files/d239f3ed02db5d9c489a651927f41f5a2f5c96e3" alt=""><figcaption></figcaption></figure>

5. 导入 TMP Essentials 后，你可以删除场景中触发 Prompt 窗口出现的空 GameObject。

<figure><img src="/files/fdfbf9528e758a74b28285f3d62dd9d950dfc38f" alt=""><figcaption></figcaption></figure>

6. 通过前往“ *文件 / 构建设置 / 构建* ”。请确保“ **Convai Demo - AR** ”场景已包含在 Scenes in Build 部分中。

<figure><img src="/files/d9ab7df030d3b65026486985bf99141a105b132c" alt=""><figcaption></figcaption></figure>

{% hint style="warning" %}
请确保已设置你的 API 密钥。（Convai / Convai Setup）
{% endhint %}

现在一切都已准备好，可以测试了。🙂✅

### 方法 2：手动设置

{% hint style="danger" %}
请确保你的项目中已安装以下包：

* ARCore
* URP（Universal Render Pipeline）- 推荐用于优化，但并非必需
  {% endhint %}

1. 双击“Convai / Convai Custom Unity Packages / ConvaiVRUpgrader.unitypackage”

<figure><img src="/files/9ae41dad46a57e54dd2030db2f583a4b556d9b07" alt=""><figcaption></figcaption></figure>

2. 你会看到一个警告，提示这些设置将覆盖你的项目设置。你可以点击“ **导入** ”或者通过点击“ **切换项目** "

<figure><img src="/files/0620aa41571ffd080d2967c9de436d068e126e53" alt=""><figcaption></figcaption></figure>

3. 在 Import Unity Package 窗口中，查看将要导入的资源并点击“ **下一步** "

<figure><img src="/files/f5b7274ea72d168c50643aff7d6e681d5d270967" alt=""><figcaption></figcaption></figure>

4. 选择 Project Settings 中所有要更改的设置，然后点击“ **导入** "

<figure><img src="/files/5b3c1d012463c6bdf1e9916122200222a99d1052" alt=""><figcaption></figcaption></figure>

5. 打开“ *Convai / Scenes / Convai Demo - AR* ”演示场景。如果出现 TMP 导入器窗口（如果你的项目中未安装 TMP Essentials，就会出现），点击“ **导入 TMP Essentials** ”以安装用于 UI 文本对象的 TextMeshPro Essentials。

<figure><img src="/files/641890529b0394cd48ede9bc1f464e4e5c44b1f4" alt=""><figcaption></figcaption></figure>

或者，你可以使用“ *Window / TextMeshPro / 导入 TMP 基础资源* ”来安装它。

<figure><img src="/files/d239f3ed02db5d9c489a651927f41f5a2f5c96e3" alt=""><figcaption></figcaption></figure>

6. 导入 TMP Essentials 后，你可以删除场景中触发 Prompt 窗口出现的空 GameObject。

<figure><img src="/files/fdfbf9528e758a74b28285f3d62dd9d950dfc38f" alt=""><figcaption></figcaption></figure>

7. 如果你看到 3D 对象呈粉色，那是着色器问题。如果你正在使用 URP，请双击“ *Convai / Convai Custom Unity Packages / ConvaiURPConverter* ”并导入弹出窗口中的所有资源。

<figure><img src="/files/14fcac47aec2011ea8ebffa1baaf4b1c5a80d4a2" alt=""><figcaption></figcaption></figure>

8. 请确保已设置你的 API 密钥（Convai / Convai Setup）。
9. 通过前往“ *文件 / 构建设置 / 构建* ”。请确保“ **Convai Demo - AR** ”场景已包含在 Scenes in **构建** 部分开始。

<figure><img src="/files/d9ab7df030d3b65026486985bf99141a105b132c" alt=""><figcaption></figcaption></figure>

现在一切都已准备好，可以测试了。🙂✅

## 如何添加并调整我自己的角色大小？

如果你在 convai.com playground 上创建了一个 Ready Player Me 角色，并想将其添加到你的 AR 项目中，请按照以下步骤操作：

1. 右键单击“ *Convai / ConvaiAR / Prefabs / Convai NPC AR Base Empty Character* ”预制体。
2. 点击“ *创建 / 预制体变体* "

<figure><img src="/files/f039819530a5590510e1c02f9563d2004fb05718" alt=""><figcaption></figcaption></figure>

3. 你会看到为“ **Convai NPC AR Base Empty Character** "
4. 双击这个预制体变体。

<figure><img src="/files/11e5434c05359639c3aa2eb3048849a8af31d9c0" alt=""><figcaption></figcaption></figure>

5. 在 Hierarchy 部分，将你导入的角色作为该预制体变体的子对象添加进去。

<figure><img src="/files/4fb1c79c090fa553895eae308fbc2d2b26e60f7a" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
使用“ [导入 Ready Player Me（RPM）角色](/api-docs/zh/cha-jian-yu-ji-cheng/unity-plugin/unity-importing-ready-player-me-rpm-characters.md) ”指南将你的角色添加到项目中。
{% endhint %}

6. 添加角色后，点击你的角色。
7. 在 Inspector 中，根据需要调整 Scale 设置。为了防止你的角色在说话时随动画移动，请禁用“ **应用根运动** ”选项。

<figure><img src="/files/87dbce982b76b552fe363937d17013f8ee9ff693" alt=""><figcaption></figcaption></figure>

8. 完成这些步骤后，按以下键保存你的预制体变体 **CTRL + S**.
9. 打开“ *Convai / Scenes / Convai Demo - AR* ”场景。
10. 点击“ **Convai AR Player** ”对象，位于“ **ConvaiAR Base Scene** "

<figure><img src="/files/a4b93aa459b03a2777ff19205b6de15784bcc97b" alt=""><figcaption></figcaption></figure>

11. 在 Inspector 中，在“ **Convai Character Spawner** ”组件下，将你的预制体变体添加到 **Character Prefab** 字段中。

<figure><img src="/files/1d18a74eb57e84acc8983c26b46a968cb62cf364" alt=""><figcaption></figcaption></figure>

现在，一切都已准备好，可以在 AR 环境中测试你的角色了！🙂✅

{% hint style="success" %}
创建这个预制体变体是为了防止你的预制体在 AR 环境中实例化时自动缩放为（1,1,1）。

为避免缩放调整问题，我们将角色作为一个空父对象的子对象添加。为了方便起见，我们创建了一个空的预制体变体。
{% endhint %}


---

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

```
GET https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/unity-plugin/building-for-supported-platforms/convai-xr/building-for-ar.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
