# 如何手动集成 Text Animator

***嘘。检查你的对话系统是否已经集成在这里：*** [集成的插件与对话系统](/text-animator-unity/2.x-zh/ji-cheng/ji-cheng-de-cha-jian-yu-dui-hua-xi-tong.md).

所有对话系统都不同，但有一点例外： **设置文本**.\
\&#xNAN;*理论上* 你可以简单地通过替换“`tmpro.text=dialogue;`”为“`typewriter.ShowText(dialogue);`”来集成你的插件，但这里有一个更详尽的包含不同情况的指南。

请注意 **强烈建议** 禁用你的插件打字机（如果你打算使用它）并且 **使用 TextAnimator 的** 那个（这样你就可以使用它的所有功能）。

{% hint style="danger" %}
具有自身格式化功能的对话系统可能会使此过程更加复杂。有关更多信息，请阅读下图。
{% endhint %}

![](/files/c513271d3a2b256c84c2f4f38e979f5cc3934355)

**如果你需要更多说明或帮助，请随时联系我们。**

***

这里也有一份书面指南。

### 如果你的对话系统 / 插件… <a href="#if-your-dialogue-system--plugin" id="if-your-dialogue-system--plugin"></a>

### … ⚠️ 动态显示文本（有打字机效果） <a href="#shows-text-dynamically-has-a-typewriter" id="shows-text-dynamically-has-a-typewriter"></a>

✔️ 用 TextAnimator 的打字机替换你插件的打字机。

❌ 如果你无法替换 DialogueSystem 的打字机，尝试将值“`使用简单集成`”设为 false（TextAnimator 组件）并检查动画是否正常工作（基于众多不同的对话系统，无法保证成功）。\
**然而不建议使用此选项，因为性能可能会大幅波动。请使用内置的打字机。**

#### 常见问题

<details>

<summary><strong>为什么我应该使用内置的打字机？</strong></summary>

除了确保插件的预期兼容性外，你还应该出于性能原因使用内置的打字机（TextAnimatorPlayer）。

* 每次你更改 TextMeshPro 文本时，它都必须计算格式并更新网格（法线、切线、UV 等）。现在想象一下每次用打字机添加一个字母都做这种计算…… :/（不论你是否使用 Text Animator）<br>
* 因此 TMPro 添加了一个“maxVisibleCharacters”变量；你只需设置完整文本一次，然后随时间增加可见字符。一旦你使用 Text Animator，代替调用 `tmproText.maxVisibleCharacters++`，你可以简单地调用“`textAnimator.maxVisibleCharacters`”，它以类似方式工作，但也会管理你所有的效果。

</details>

<details>

<summary><strong>我的打字机是一次性设置文本并仅递增可见字符，我可以使用它吗？</strong></summary>

你可以，但你必须修改“`tmpro.maxVisibleCharacters++`”部分并将其替换为 `textAnimator.maxVisibleCharacters++`。你还必须实现 TextAnimator 的事件和功能，因为它们由 TextAnimatorPlayers 处理，未实现的话将无法工作。

</details>

### … 有自定义动作 <a href="#has-custom-actions" id="has-custom-actions"></a>

“自定义动作”是指“在显示文本时执行的动作”，比如“等待玩家输入”等。

* ✔️ 如果你正在使用一个 `TextAnimatorPlayer`：\
  在此处阅读如何实现自定义动作： [编写自定义动作（C#）](/text-animator-unity/2.x-zh/tong-guo-c-jin-xingewai-zi-ding-yi/bian-xie-zi-ding-yi-dong-zuo-c.md)
* ❌ 如果你不能使用一个 `TextAnimatorPlayer`：\
  你不需要实现任何自定义动作（因为它们已经存在于对话系统的打字机中）。不过如你所知，使用外部打字机并不推荐，可能会影响你项目的性能。

### … 有它自己的标签/格式化 <a href="#has-its-own-tagsformatting" id="has-its-own-tagsformatting"></a>

#### ✔️ 用于姓名/管理的标签 <a href="#tags-for-namesmanagement" id="tags-for-namesmanagement"></a>

这些标签应由 DialogueSystem 用来构建文本字符串。它们不应引起任何问题，因此你不必替换或修改任何内容（包括起始和结束字符）。假设的“姓名/管理”标签示例：

* `{actor1}` → 在文本中写入正在说话的第一个角色的名字。
* `|getValue("eatenApple")|` → 在文本中写入一个变量
* 文本示例

`"{actor1}, why did you eat |getValue("eatenApple")| apples?! Omg"` → “Karen, why did you eat 1234567 apples?! Omg” → 如你所见，最终文本中不显示任何标签。此情况在不需要任何 Text Animator 实现的情况下即可工作。

#### ⚠️ 文本样式的标签 <a href="#tags-for-text-styles" id="tags-for-text-styles"></a>

如果你的对话系统有样式文本标签（比如 `<bold>` 用于加粗），请确保你的对话系统的标签与 Text Animator 和 Text Mesh Pro 的标签相匹配（在上例中，将 `<bold>` 替换为 `<b>`).

#### ⚠️ 用于自定义功能的标签 <a href="#tags-for-custom-functionalities" id="tags-for-custom-functionalities"></a>

如果你的对话系统有执行任何操作的标签（例如“播放音频”），请查看这里： [编写自定义动作（C#）](/text-animator-unity/2.x-zh/tong-guo-c-jin-xingewai-zi-ding-yi/bian-xie-zi-ding-yi-dong-zuo-c.md)

另外，请务必检查已实现的功能： [在打字时等待动作](/text-animator-unity/2.x-zh/typewriter/zai-da-zi-shi-deng-dai-dong-zuo.md)


---

# Agent Instructions: 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.febucci.com/text-animator-unity/2.x-zh/ji-cheng/ru-he-shou-dong-ji-cheng-text-animator.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.
