TextMeshProMax
The ultimate Unity Text Mesh Pro helper package.
Install / Use
/learn @kwan3854/TextMeshProMaxREADME
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
SaveorApply - open Window/Package Manager
- click
+ - select
Add package by name...orAdd package from git URL... - paste
com.kwanjoong.textmeshpromaxinto 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.6.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
TextRectInfocontainingRectsand theTargetString.
- A list of
[!IMPORTANT] Coordinate System The returned
Rectvalues are in the local space of the text object's transform.Breaking Change Notice: In versions prior to
0.6.0, theRectforTextMeshProUGUIwas returned in the Canvas's local space. This has been changed to consistently use the text object's local space for allTMP_Texttypes. Please update your implementation accordingly.
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:trueif successful.
[!IMPORTANT] Coordinate System The returned
Rectvalues are in the local space of the text object's transform.Breaking Change Notice: In versions prior to
0.6.0, theRectforTextMeshProUGUIwas returned in the Canvas's local space. This has been changed to consistently use the text object's local space for allTMP_Texttypes. Please update your implementation accordingly.
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(RubyTextMeshProUGUIorRubyTextMeshPro): The target RubyTextMeshProUGUI object.rubyString(RubyString): A collection ofRubyElemententries 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
TextRectInfoobjects, each containing:Rects: A list ofRectobjects for the string or line.TargetString: The concatenated plain text of the Ruby string.
[!IMPORTANT] Coordinate System The returned
Rectvalues are in the local space of the text object's transform.Breaking Change Notice: In versions prior to
0.6.0, theRectforTextMeshProUGUIwas returned in the Canvas's local space. This has been changed to consistently use the text object's local space for allTMP_Texttypes. Please update your implementation accordingly.
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
Related Skills
node-connect
338.7kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
83.6kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
338.7kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
commit-push-pr
83.6kCommit, push, and open a PR
