TextTyper is a text typing effect component for Unity. TextTyper prints out characters one by one to a uGUI Text component. Adapted by RedBlueGames from synchrok's GitHub project (https://github.com/synchrok/TypeText). - Forked by Rakkoono from Laicasaane's edit
It's easy to find other examples of Text printing components, but TextTyper provides two major differences:
- Correct wrapping as characters are printed
- Support for Rich Text Tags
Note this version of TextTyper requires TextMeshPro, which can be installed for free from the Package Manager in Unity 2020, or the Asset Store in older versions. If you want the version that is compatible with Unity's uGUI Text component, this branch or download this release.
To start TextTyping all you need to do is add the TextTyper
component to a unity Text widget:
- Create a GameObject with a Unity UI Text Widget, as normal.
- Add a TextTyper component to the GameObject.
- Call the TextTyper component's public functions
TypeText
andSkip
to print the desired text with the specified delay. We call these from a 3rd component we callTalker
.
You can optionally subscribe to the PrintCompleted
and CharacterPrinted
UnityEvents to add additional feedback like sounds and paging widgets.
- Define Text Speed Per Character:
Mayday! <delay=0.05>S.O.S.</delay>
- Support for uGUI Rich Text Tags:
<b>,<i>,<size>,<color>,...
- Additional delay for punctuation
- Skip to end
- OnComplete Callback
- OnCharacterPrinted Callback (for audio)
- Custom Animations
- Custom Tags with arguments
- Example Scene, Libraries, Config & Tester Script
- Add
TextLibrary
scriptable object, so you can easily add your own tags made of other ones
- Add
PrintAmount
to the config to support printing any number of characters each time.
- The fields named
PunctuationCharacters
insideTextTyper
andTextTyperConfig
have been renamed toPunctuations
. Their type has been changed toList<string>
TextSymbol
class has been moved out ofTextTagParser
- The constructors of
TextSymbol
has been changed intoInitialize(...)
methods TextTagParser
is now a static class- The signature of
TextTagParser.CreateSymbolListFromText(...)
has been changed. It now requires aList<TextSymbol>
parameter to reduce allocation TextTagParser
now uses a pool ofTextSymbol
to reduce allocation- Add
Pause()
andResume(...)
methods toTextTyper
- Add
TextTyperConfig
field toTextTyper
to allow overriding default settings:PrintDelay
,PunctuationDelayMultiplier
,PunctuationCharacters
TextTyper.TypeText(...)
can now receive an instance ofTextTyperConfig
as an alternated config. It's only valid until the next invocation ofTypeText(...)
TextTyper
now requiresTMP_Text
instead ofTextMeshProUGUI
The core of our text typer is a coroutine that’s triggered via the TypeText method. The coroutine has the following steps: Check next character to see if it’s the start of a Rich Text tag
- If It’s a tag, parse it and apply it. Right now “applying” a tag just means modifying the print delay, but other tags could be added. Add it to a list of tags that need to be closed (because we have not yet reached the corresponding closing tag in our string). Move to next character and repeat
- If it’s not a tag, print it
- Wait for the print delay
- Check if we are complete
The tool also uses RichTextTag.cs, a class that’s used to help with parsing. There are a few details I left out, but this should give you enough to start reading through the code if you want to know more.
The easiest way to help with the project is to just to use it! As you use it, you can submit bugs and feature requests through GitHub issues.
Issue Resporters
- JonathanGorr
- TypeText is under MIT license. See the LICENSE file for more info.
- Typing sound effect (UITextDisplay.wav) provided by @kevinrmabie. Free for others to use, no attribution necessary.