自定义 Text Behaviour Component
我们已经在 Text Behaviour Profile 章节中了解到,一个 Profile 由多个 Text Behaviour Component 组成,它们定义了该 Profile 如何影响文本动画的行为。
你可以在 内置 Text Behaviour Components 章节中查看默认提供的组件列表。
不过,如果你有更高级的定制需求,也可以自己编写一个 C# 的 Text Behaviour Component 脚本。
创建 Text Behaviour Component 脚本
打开 Assets 菜单,选择 Create -> Sequine -> C# Text Behaviour Component,创建一个新的脚本。将文件命名为 ExampleTextBehaviourComponent(可选)。
下面是脚本的默认内容。
ExampleTextBehaviourComponent.cs
using TMPro;
using UnityEngine;
using Calcatz.Sequine;
public class ExampleTextBehaviourComponent : TextBehaviourComponent
{
public override bool overrideGeometry => false;
public override bool overrideVertexData => false;
public override void HandleCharacterBehaviour(CharacterData _characterData,
TMP_Text _textComponent,
TMP_TextInfo _textInfo,
TMP_MeshInfo[] _meshInfo,
Bounds _meshBounds,
float _segmentNormalizedTime)
{
}
}
- 如果我们的计算需要更新 TextMeshPro 组件的几何数据,可以把 overrideGeometry 属性重写为
true。 - 如果我们的计算需要更新 TextMeshPro 组件的顶点数据,可以把 overrideVertexData 属性重写为
true。
关于参数:
- 如果计算涉及某个追加文本段的网格边界,可以使用 meshBounds。
- 如果计算涉及当前追加文本段在持续时间中的百分比,可以使用 segmentNormalizedTime。
如果你在想 追加文本段 是什么意思,回想一下,在 Sequine Text 中,每次追加字符串时,都可以为这段追加的文本应用不同的 behaviour profile。
剩下的内容更多属于 TextMeshPro 本身的定制,而不是 Sequine 的部分。因此,你可以查阅 TextMeshPro Documentation 来进一步学习。