# 编写自定义输入等待（C#）

通过使用“Text Animator for Unity”，你可以创建你自己的 **自定义打字机等待**，在字母之间设置不同类型的延迟以及更多功能。

{% hint style="info" %}
如果你想了解默认的打字机， [请在此阅读](/text-animator-unity/3.x-zh/da-zi-ji/dong-tai-xian-shi-he-yin-cang-zi-mu.md)
{% endhint %}

{% hint style="info" %}
请务必已阅读 [高级概念](/text-animator-unity/3.x-zh/bian-xie-zi-ding-yi-lei/gao-ji-gai-nian.md) 页面。
{% endhint %}

***

## 添加自定义打字机等待 <a href="#adding-custom-typewriters" id="adding-custom-typewriters"></a>

为了创建自定义打字机等待，你需要创建一个继承自的可脚本化对象类 `Febucci.TextAnimatorForUnity.TypingsTimingsScriptableBase`

下面是一个简单的示例脚本：

<pre class="language-csharp"><code class="lang-csharp">// 导入必要的 Febucci 命名空间
<strong>using Febucci.TextAnimatorCore;
</strong><strong>using Febucci.TextAnimatorCore.Text;
</strong><strong>using Febucci.TextAnimatorForUnity;
</strong>
using UnityEngine;

[System.Serializable] // &#x3C;--- 记得序列化你的 Scriptable！
[CreateAssetMenu(fileName = "Custom Typewriter Waits")]
<strong>class CustomTypingWaits : TypingsTimingsScriptableBase
</strong>{
    // --- 像平常一样在此处放置你的属性
    [SerializeField] float delay = .1f;
    
    // 显示文本时的自定义等待
<strong>    public override float GetWaitAppearanceTimeOf(CharacterData character, TextAnimator animator)
</strong>    {
        // 示例：跳过空格
        if (char.IsWhiteSpace(character.info.character))
            return 0;

        return delay;
    }

    // 文本消失时的自定义等待
<strong>    public override float GetWaitDisappearanceTimeOf(CharacterData character, TextAnimator animator)
</strong>    {
        // 在这种情况下，它与显示时相同
        return GetWaitAppearanceTimeOf(character, animator);
    }
}
</code></pre>

***

{% hint style="success" %}
就是这样！&#x20;
{% endhint %}

{% hint style="warning" %}
别忘了在你的资源文件夹中创建该可脚本化对象，并将其分配给你的 Typewriter 组件。更多内容请阅读： [动态显示和隐藏字母](/text-animator-unity/3.x-zh/da-zi-ji/dong-tai-xian-shi-he-yin-cang-zi-mu.md)
{% endhint %}

祝你在实现你自己的打字机时玩得开心 <3


---

# 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/bian-xie-zi-ding-yi-shu-ru-deng-dai-c.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.
