Skip to main content

Custom Text Behaviour Component

We've learned from Text Behaviour Profile section, that a profile consists of several Text Behaviour Components that defines how to profile affects the behaviour of the text animation.

We can see the list of the available components that is provided by default in Text Behaviour Components section.

However, if we hava a more advanced need to customize the behaviour, we can create a custom C# Text Behaviour Component script.

Creating a Text Behaviour Component Script

Create a new Text Behaviour Component script by opening the Assets menu and choose Create -> Sequine -> C# Text Behaviour Component. Name the new file to ExampleTextBehaviourComponent (optional).

Here's how to script looks like by default.

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)
{

}

}
  • Override the overrideGeometry property to true if our calculation should update the geometry of the TextMeshPro component.
  • Override the overrideVertexData property to true if our calculation should update the vertex data of the TextMeshPro component.

For the parameters,

  • We can use meshBounds if we need a calculation that involves a mesh bound of certain appended text segment.
  • We can use segmentNormalizedTime if we need a calculation that involves the percentage of the current duration of the appended text segment.

If you are wondering what appended text segment means, remember that in Sequine Text, when we append a string, we can apply a different behaviour profile on each appended text.

The rest is more of a TextMeshPro customization rather than Sequine. So, you can check on the TextMeshPro Documentation to learn more.