# 高级概念

在幕后，Text Animator 正在做大量工作和优化以确保：

* 动画期间没有垃圾回收 *（在设置文本时仍然会有一些垃圾回收，TMPro 和 Text Animator 2.0 也是如此，但我们正在努力解决！）*
* 该资源与不同的 Unity 版本、系统和平台兼容
* 为你提供尽可能简单的 API *（把痛苦留给我们，但这正是目的！）*
* 即使在存在错误设置或空引用的情况下，功能也能尽可能正常工作

也就是说，当你开始编写自定义脚本时，Text Animator for Unity 内部有一些关键概念需要了解：

* [#core-library](#core-library "mention")
* [#stateless-vs-referenced-elements](#stateless-vs-referenced-elements "mention")

***

## 核心库

Text Animator 被分为两个主要命名空间：

* “`Febucci.TextAnimatorCore`” 是我们的 **核心库，** 这是随包一起提供的运行时 DLL，是使一切正常工作的基础。
* “`Febucci.TextAnimatorUnity`” 是 **Unity 实现，**&#x4ECE;可脚本化对象到 MonoBehaviours 等。

你将在接下来的页面/指南中找到如何按预期设置脚本，但请注意你继承、修改或重新实现的内容！

我会持续更新核心库以实现新功能或重组结构，而不可能预见人们在 C# 中可能做出的各种变体和用例（尤其是非预期的情况）——所以请遵循指南！无论如何我会尽可能将内容标记为 internal，并尽量保持 Unity 实现跨版本向后兼容（像我过去这些年一直做的那样，必要时也会包含更新指南）——但如果你要做一些未计划的修改，请自担风险！

{% hint style="warning" %}
如果你在项目进行中升级 Unity 版本，请从包管理器中移除该资源并重新下载（它会在幕后下载为该 Unity 版本构建的包！）

[/pages/5d2f4209e7ffada8a20723ff5d38db7fe20efa96#i-upgraded-unity-version-2022.3-greater-than-unity-6.3-and-there-are-some-errors-with-text-animator](https://docs.febucci.com/text-animator-unity/3.x-zh/bian-xie-zi-ding-yi-lei/pages/5d2f4209e7ffada8a20723ff5d38db7fe20efa96#i-upgraded-unity-version-2022.3-greater-than-unity-6.3-and-there-are-some-errors-with-text-animator "mention")
{% endhint %}

## 无状态 vs 有引用的元素

大多数 Text Animator 元素（包括效果、动作、播放器和曲线）有两种实现方式。一种独立于 Unity 和 GameObject/ScriptableObject，另一种则保留来自游戏状态/文件和类的引用。

<table data-full-width="true"><thead><tr><th width="120.5">类型</th><th>优点</th><th>缺点</th></tr></thead><tbody><tr><td>无状态</td><td><ul><li>更佳的优化（将来也为 Burst 做好准备，待定）</li><li>元素之间不存在竞争条件</li></ul></td><td><ul><li>有一些代码封装，但通过资源的自定义类进行了缓解！</li><li>无法基于游戏状态修改动画/打字效果</li></ul></td></tr><tr><td>有引用的</td><td><ul><li>可以访问游戏状态并根据其不同地触发行为</li></ul></td><td><ul><li>如果实现不当可能出现竞争条件（例如两个打字器同时访问同一个具有计时器或触发行为的动作）</li><li>不能通过 Burst 优化（但大多数情况下应可忽略，因为内置部分承担了主要开销） </li></ul></td></tr></tbody></table>

{% hint style="info" %}
我们也在研究一种方式，为你提供 ***直接*** 元素，意思是：移除我们所有的实现，只让你以你想要的方式挂接（鉴于现有的其他工具，这应只适用于大约 1% 的用户，但在我们看来仍然是一个重要选项）。

* **优点**: 自己动手。
* **缺点**: 自己动手。
  {% endhint %}

如何自定义你的元素由你决定。

* 在性能关键的场景下（例如存在大量字母时）选择无状态类型


---

# 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/3.x-zh/bian-xie-zi-ding-yi-lei/gao-ji-gai-nian.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.
