Skip to content

Extend Unity TextMeshPro with custom tags and text animations

License

MIT, Unknown licenses found

Licenses found

MIT
LICENSE
Unknown
LICENSE.meta
Notifications You must be signed in to change notification settings

oneir0mancer/tmpro-custom-tags

Repository files navigation

Custom tags and text animation for TMP

Example

This package aims to implement a more clean and robust way to extend TMP with custom tags.

Instead of using <link> tags (which is really clunky), the idea is to use a ITextPreprocessor to parse tags, and then update text mesh using that information.

This repository is a proof-of-concept, so don't expect it to be stable.

Install

I recommend to fork or clone this repository, for when something inevitably needs to be fixed.

But if you want to install it as package:

  1. Select in UPM "Add package from git URL..."
  2. Install via link
https://github.com/oneir0mancer/tmpro-custom-tags.git

Custom Tags

Creating custom text effect

To create custom text effect inherit from BaseTextEffect, which lets you modify vertices' information every frame.

Code Example
public class CustomTextEffect : BaseTextEffect
{
    public override string Tag => "custom_tag";
    
    protected override void ApplyToCharacter(TMP_Text text, TMP_CharacterInfo charInfo)
    {
        // YOUR IMPLEMENTATION
    }
}

In order to reference this new tag in Inspector, you will also need to create a ScriptableObject wrapper for this class.

Code Example
[CreateAssetMenu(menuName = "TMP Custom Tags/Custom Effect")]
public class CustomTextEffectSo : TextEffectSoWrapper<CustomTextEffect>
{ }

Using custom text effect

In order to use custom tags, add TagParser compontent to your gameobject with TMP_Text, and supply ScriptableObjects for all custom tags used.

You can preview them if you RMB the component and choose corresponding context menu option. Just note that while in editor mode Unity doesn't redraw scene or game view every frame.

Typewriter Animation

This component will animate text appearing character by character. Since every step will regenerate text mesh, interfering with effects, we cache vertex data right before the step, and restore it after mesh was regenerated.

Limitations

  • Tag preprocessor is very bare-bones, so any unknown tag will interfere with where other tags start and end.
  • You need to create a ScriptableObject wrapper for every tag to use them in Inspector. I'm working on a component that would eliminate that by using [SerializedReference].

About

Extend Unity TextMeshPro with custom tags and text animations

Topics

Resources

License

MIT, Unknown licenses found

Licenses found

MIT
LICENSE
Unknown
LICENSE.meta

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages