Awesome
TextMeshProMax
<img src="Documentation~/Images/logo.png" alt="How to enable xml comments" width="700" />
TextMeshProMax is a utility library that extends TextMesh Pro
, making it easier to perform advanced text-related tasks in Unity projects. It supports standard TextMesh Pro functionalities and optional RubyTextMeshPro integration.
Table of Contents
<!-- START doctoc generated TOC please keep comment here to allow auto update --> <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->Details
<!-- END doctoc generated TOC please keep comment here to allow auto update -->Roadmap
You can find the roadmap for this project in the Roadmap section.
How to Install
1. Install via OpenUPM
1.1. Install via Package Manager
Please follow the instrustions:
- open Edit/Project Settings/Package Manager
- add a new Scoped Registry (or edit the existing OpenUPM entry)
- Name:
package.openupm.com
- URL:
https://package.openupm.com
- Name:
- click
Save
orApply
- open Window/Package Manager
- click
+
- select
Add package by name...
orAdd package from git URL...
- paste
com.kwanjoong.textmeshpromax
into name - paste version (e.g.
0.5.2
) into version - click
Add
1.2. Alternatively, merge the snippet to Packages/manifest.json
{
"scopedRegistries": [
{
"name": "package.openupm.com",
"url": "https://package.openupm.com",
"scopes": []
}
],
"dependencies": {
"com.kwanjoong.textmeshpromax": "0.5.2" // Please use the latest version
}
}
1.3. Install via command-line interface
openupm add com.kwanjoong.textmeshpromax
2. Install via Git URL
- Open package manager from Unity Editor
Window
->Package Manager
->+
button on top left ->Add package from git URL
- Copy and paste this url
https://github.com/kwan3854/TextMeshProMax.git
- If you need specific version, you can specify like this
https://github.com/kwan3854/TextMeshProMax.git#v0.2.0
[!TIP] You can see inline comments in the code editor by enabling this option in the Unity Editor:
Edit
->Preferences
->External Tools
->Generate .csproj files
<img src="Documentation~/Images/xml_settings.png" alt="How to enable xml comments" width="700" />
Features
Helper Features
1. GetStringRects
Retrieve the Rect information for specific strings rendered by a TMP_Text
object.
- Parameters:
text
(TMP_Text
): The target TextMesh Pro object.targetString
(string
): The string you want to locate in the text.findMode
(TextFindMode
):TextFindMode.First
: Returns the first occurrence.TextFindMode.All
: Returns all occurrences.
- Returns:
- A list of
TextRectInfo
containingRects
and theTargetString
.
- A list of
Code Example
using Runtime.Helper;
using TMPro;
using UnityEngine;
public class TMPExample : MonoBehaviour
{
private TMP_Text _text;
void Start()
{
// Initialize TMP_Text
_text = GetComponent<TMP_Text>();
_text.text = "Hello World\nHello Universe";
// Retrieve Rect information for all occurrences of "Hello"
var rects = _text.GetStringRects("Hello", TextFindMode.All);
foreach (var rectInfo in rects)
{
foreach (var rect in rectInfo.Rects)
{
Debug.Log($"BottomLeft: {rect.min}, TopRight: {rect.max}, String: {rectInfo.TargetString}");
}
}
}
}
// Works on any tmp: TMP_Text, TextMeshPro, TextMeshProUGUI
TMP_Text text;
TextMeshPro text;
TextMeshProUGUI text;
text.text = "Hello World\nHello Universe";
var rects = text.GetStringRects(rubyString, TextFindMode.All);
1.1 TryGetStringRects
Attempt to retrieve the Rect information for specific strings rendered by a TMP_Text
object. Returns true
if successful, false
otherwise.
- Parameters:
- Same as
GetStringRects
. - Adds
out results
(List<TextRectInfo>
).
- Same as
- Returns:
bool
:true
if successful.
Code Example
List<TextRectInfo> results;
if (text.TryGetStringRects("Hello", TextFindMode.All, out results))
{
foreach (var rect in results)
{
Debug.Log("Rect Found: " + rect);
}
}
2. GetRubyStringRects (Requires RubyTextMeshPro)
Retrieve Rect information for Ruby strings, including body and Ruby text.
Parameters
rubyText
(RubyTextMeshProUGUI
orRubyTextMeshPro
): The target RubyTextMeshProUGUI object.rubyString
(RubyString
): A collection ofRubyElement
entries combining Ruby, body, and plain text.findMode
(TextFindMode
):TextFindMode.First
: Returns the first occurrence of the Ruby string.TextFindMode.All
: Returns all occurrences of the Ruby string.
Returns
- A list of
TextRectInfo
objects, each containing:Rects
: A list ofRect
objects for the string or line.TargetString
: The concatenated plain text of the Ruby string.
Code Example
using Runtime.Helper;
using TMPro;
using UnityEngine;
public class RubyTMPExample : MonoBehaviour
{
private RubyTextMeshProUGUI _text;
void Start()
{
// Initialize RubyTextMeshProUGUI
_text = GetComponent<RubyTextMeshProUGUI>();
_text.uneditedText = "<r=domo>Hello</r> <r=sekai>World</r> This is normal text!";
// Parse RubyTextMeshPro's plain text
Debug.Log($"PlainText: {_text.GetParsedText()}");
// Create RubyString
var rubyString = new RubyString(new List<RubyElement>
{
new RubyElement("Hello", "domo"),
new RubyElement(" "), // Space
new RubyElement("World", "sekai"),
new RubyElement(" This is normal text!") // Plain text
});
// Retrieve Rect information
var rects = _text.GetRubyStringRects(rubyString, TextFindMode.All);
foreach (var rectInfo in rects)
{
foreach (var rect in rectInfo.Rects)
{
Debug.Log($"BottomLeft: {rect.min}, TopRight: {rect.max}, String: {rectInfo.TargetString}");
}
}
}
}
// Works on both RubyTextMeshPro(3D text) and RubyTextMeshProUGUI(2D UI text)
RubyTextMeshProUGUI text;
RubyTextMeshPro text;
text.uneditedText = "<r=domo>Hello</r> <r=sekai>World</r> This is normal text!";
var rects = text.GetRubyStringRects(rubyString, TextFindMode.All);
2.1 TryGetRubyStringRects (Requires RubyTextMeshPro)
Attempt to retrieve the Rect information for complex Ruby strings rendered by a RubyTextMeshProUGUI
object. Returns true
if successful, false
otherwise.
3. Multi-Line Support
The library can calculate Rect
values for text that spans multiple lines. Whether the line breaks are due to manual newlines (\n
) or automatic text wrapping applied by TextMesh Pro, the library handles them seamlessly.
[!TIP] If the target string crosses line boundaries, the library automatically splits the result into one
Rect
per line, regardless of whether the line break was introduced manually or by automatic word wrapping.
Example:
For the text:
Hello
World!
If the target string is "Hello\nWorld!"
, the result will include two Rect
objects:
- One for
"Hello"
- One for
"World!"
For the text:
Hello very long
text that wraps!
If the target string is "Hello very long text that wraps!"
, the result will include two Rect
objects:
- One for
"Hello very long"
- One for
"text that wraps!"
Tools
TMP Font Batch Changer
The TMP Font Batch Changer automates the process of finding and replacing fonts across scenes and prefabs.
<img src="Documentation~/Images/font_batch_changer_1.png" alt="CJK Baking Tool" width="700" /> <img src="Documentation~/Images/font_batch_changer_2.png" alt="CJK Baking Tool" width="700" />[!CAUTION] Always back up your project before performing bulk operations. We do not guarantee compensation for any damage or loss caused by using this tool.
How to Use
- Open the tool:
Tools
->TextMeshPro Max
->TMP Font Batch Changer
- Set up:
- New Font Asset: Font to apply.
- Prefab Root Folder: Folder to search for prefabs.
- Scene Selection: Select scenes to scan.
- Click Search TMP_Text Components.
- Review and apply changes.
[!TIP] You can ping the TMP_Text component in the scene/project by clicking the Select button.
Key Features
- Group by Font: Organize TMP_Text components by their current fonts.
- Scene and Prefab Support: Apply font changes across your project.
- Manual Review: Toggle components to selectively update.
CJK Font Atlas Generator
The CJK TextBakerProMax is a utility for creating customized TextMesh Pro font atlases optimized for CJK (Chinese, Japanese, Korean) characters. It generates Dynamic Atlases, ensuring text rendering flexibility without pre-baking static font assets.
How to Use
- Open the tool:
Tools
->TextMeshPro Max
->CJK Font Atlas Generator
<img src="Documentation~/Images/CJK_baker_2.png" alt="CJK Baking Tool" width="700" />
[!WARNING] Disable the "Clear Dynamic Data On Build" option to retain character atlases in builds. This option is located in inspector of the generated font asset. (or in the TMP Settings for all fonts)
Why Use This Tool?
By default, dynamic font atlases in TextMesh Pro allow you to use fonts without worrying about missing characters. Characters are added to the atlas dynamically as needed. However, there are specific cases where you might want to predefine a set of characters in the atlas to avoid runtime performance issues:
- High-density text rendering: For example, chat applications, subtitles, or text-rich interfaces where a large number of characters are displayed at once.
- Unpredictable character usage: For example, when text is dynamically loaded from servers or large datasets, and the exact characters are unknown at build time.
For most projects, especially where the text is predictable and limited in quantity, you don’t need to predefine a large set of characters. Instead, rely on the default dynamic behavior to optimize performance.
Language Options
You can select from Chinese, Japanese, and Korean. These options determine which specific ranges and subsets of characters will be included in the generated font atlas.
CJK Options
These options are shared across all three languages. They cover additional character sets commonly used in CJK writing systems. The following sections provide detailed descriptions of each range, their purpose, and when to enable them.
Detailed Options and Usage
Korean
-
KS-1001 (B0A0-C8FF)
- Description:
KS X 1001 is the South Korean character encoding standard. It includes 2,350 commonly used Hangul syllables, Hanja, and symbols.
Learn more about KS X 1001 - When to Enable:
Use this option if your project targets South Korean audiences and focuses on frequently used characters (e.g., educational apps, simple interfaces).
- Description:
-
Full Hangul (AC00-D7A3)
- Description:
This range includes all 11,172 possible Hangul syllables, covering every valid combination of Korean Jamo. - When to Enable:
Use for applications that involve extensive Korean text or unpredictable user input, such as chat apps or text-heavy games.
- Description:
-
Hangul Jamo (1100-11FF)
- Description:
Includes the individual components (consonants and vowels) used to form Hangul syllables. - When to Enable:
Choose this if your project involves advanced Korean typography or phonetic analysis, where Jamo might be displayed independently.
- Description:
-
Hangul Compatibility Jamo (3130-318F)
- Description:
Contains pre-composed Hangul Jamo blocks for backward compatibility. - When to Enable:
Use only if your application needs to support legacy Korean text encoding.
- Description:
-
Hangul Jamo Extended-A (A960-A97F)
- Description:
Additional Jamo blocks introduced in Unicode 5.2. - When to Enable:
Enable for specialized linguistic tools or projects requiring modern Korean typographic features.
- Description:
-
Hangul Jamo Extended-B (D7B0-D7FF)
- Description:
A further extension of Hangul Jamo for rare or historic Korean text. - When to Enable:
Enable only if you are working on historic Korean text or rare linguistic projects.
- Description:
Japanese
-
Hiragana (3040-309F)
- Description:
The basic phonetic script used in Japanese. Includes 83 characters.
Learn more about Hiragana - When to Enable:
Use for any Japanese text rendering, as Hiragana is fundamental to the language.
- Description:
-
Katakana (30A0-30FF)
- Description:
The second phonetic script in Japanese, used for foreign words and emphasis. Includes 96 characters.
Learn more about Katakana - When to Enable:
Essential for Japanese text, especially in games or apps with foreign word integration or stylized text.
- Description:
-
Katakana Phonetic Extensions (31F0-31FF)
- Description:
Extensions to Katakana, mainly for Ainu language support. - When to Enable:
Use for projects involving Ainu language support or specialized Japanese typographic needs.
- Description:
Chinese
-
Common 3500 Characters
- Description:
A curated set of 3,500 frequently used Chinese characters, covering most everyday text.
Learn more about Common 3500 Characters - When to Enable:
Use for general-purpose Chinese text rendering.
- Description:
-
Common 7000 Characters
- Description:
An extended set of 7,000 Chinese characters, including less common or specialized characters.
Learn more about Common 7000 Characters - When to Enable:
Use for projects requiring a broader range of Chinese characters, such as educational apps or specialized text processing.
- Description:
CJK Options
-
CJK Unified Ideographs (4E00-9FBF)
- Description:
The core block of 20,976 Chinese, Japanese, and Korean ideographs.
Learn more about CJK Unified Ideographs - When to Enable:
Use this for general-purpose support of Chinese, Japanese, or Korean text. Essential for any CJK-focused application.
- Description:
-
CJK Unified Ideographs Extension B (20000-2A6DF)
- Description:
Includes 42,711 additional ideographs.
Learn more about Extension B - When to Enable:
Use for scholarly or historic texts requiring rare or ancient characters.
- Description:
-
CJK Compatibility Ideographs (F900-FAFF)
- Description:
A set of characters for compatibility with legacy encodings.
Learn more about CJK Compatibility Ideographs - When to Enable:
Use only for backward compatibility or applications handling legacy text files.
- Description:
-
CJK Compatibility Ideographs Supplement (2F800-2FA1F)
- Description:
Supplements the compatibility ideographs for specialized needs.
Learn more about the Supplement - When to Enable:
Enable for rare cases involving historic or specialized text processing.
- Description:
-
CJK Radicals Supplement (2E80-2EFF)
- Description:
Contains radicals used in East Asian scripts for dictionaries or indexing.
Learn more about CJK Radicals Supplement - When to Enable:
Use for dictionary applications or tools involving radical-based text analysis.
- Description:
Contributing
We welcome contributions to this project. If you have ideas for new features or improvements, feel free to open an issue or submit a pull request.
Requesting New Features
If you want to request a new feature or report a bug, please visit the Issues page of the repository and create a new issue.
License
This project is licensed under the MIT License. See the LICENSE file for details.