diff --git a/README.md b/README.md index c3460f6..095767e 100644 --- a/README.md +++ b/README.md @@ -98,7 +98,7 @@ openupm add com.kwanjoong.textmeshpromax - `Window` -> `Package Manager` -> `+` button on top left -> `Add package from git URL` 2. 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``` + - 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` @@ -123,6 +123,12 @@ Retrieve the **Rect information** for specific strings rendered by a `TMP_Text` - **Returns**: - A list of `TextRectInfo` containing `Rects` and the `TargetString`. +> [!IMPORTANT] +> **Coordinate System** +> The returned `Rect` values are in the **local space of the text object's transform**. +> +> **Breaking Change Notice**: In versions prior to `0.6.0`, the `Rect` for `TextMeshProUGUI` was returned in the Canvas's local space. This has been changed to consistently use the text object's local space for all `TMP_Text` types. Please update your implementation accordingly. + ##### Code Example ```csharp using Runtime.Helper; @@ -172,6 +178,13 @@ Attempt to retrieve the **Rect information** for specific strings rendered by a - **Returns**: - `bool`: `true` if successful. +> [!IMPORTANT] +> **Coordinate System** +> The returned `Rect` values are in the **local space of the text object's transform**. +> +> **Breaking Change Notice**: In versions prior to `0.6.0`, the `Rect` for `TextMeshProUGUI` was returned in the Canvas's local space. This has been changed to consistently use the text object's local space for all `TMP_Text` types. Please update your implementation accordingly. + + ##### Code Example ```csharp List results; @@ -201,6 +214,12 @@ Retrieve **Rect information** for Ruby strings, including body and Ruby text. - `Rects`: A list of `Rect` objects for the string or line. - `TargetString`: The concatenated plain text of the Ruby string. +> [!IMPORTANT] +> **Coordinate System** +> The returned `Rect` values are in the **local space of the text object's transform**. +> +> **Breaking Change Notice**: In versions prior to `0.6.0`, the `Rect` for `TextMeshProUGUI` was returned in the Canvas's local space. This has been changed to consistently use the text object's local space for all `TMP_Text` types. Please update your implementation accordingly. + ##### Code Example ```csharp using Runtime.Helper; @@ -255,6 +274,12 @@ 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. +> [!IMPORTANT] +> **Coordinate System** +> The returned `Rect` values are in the **local space of the text object's transform**. +> +> **Breaking Change Notice**: In versions prior to `0.6.0`, the `Rect` for `TextMeshProUGUI` was returned in the Canvas's local space. This has been changed to consistently use the text object's local space for all `TMP_Text` types. Please update your implementation accordingly. + #### 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. diff --git a/Runtime/Helper/TextMeshProExtensions.cs b/Runtime/Helper/TextMeshProExtensions.cs index 4567ff6..d57cde0 100644 --- a/Runtime/Helper/TextMeshProExtensions.cs +++ b/Runtime/Helper/TextMeshProExtensions.cs @@ -82,8 +82,7 @@ public static bool TryGetStringRects(this TextMeshProUGUI text, string targetStr /// /// Retrieves the Rect information for a specific string within a TMP_Text object. - /// For TextMeshPro (3D), the Rect values are in the text object's local space. - /// For TextMeshProUGUI (UI), the Rect values are in the canvas's local space. + /// The returned Rect values are in the local space of the text object's transform. /// /// The target TMP_Text object. /// The string to find within the text. @@ -407,7 +406,7 @@ private static bool TryGetStringRectsInternal( if (charIndexes.Count == 0) continue; // Split into lines and calculate Rect for each line - var lineRects = CalculateLineBoundingRects(charIndexes, textInfo, textBase.Transform); + var lineRects = CalculateLineBoundingRects(charIndexes, textInfo); if (lineRects.Count > 0) { @@ -427,8 +426,7 @@ private static bool TryGetStringRectsInternal( /// private static List CalculateLineBoundingRects( List charIndexes, - TMP_TextInfo textInfo, - Transform transform) + TMP_TextInfo textInfo) { var rects = new List(); var lineGroups = charIndexes @@ -438,7 +436,7 @@ private static List CalculateLineBoundingRects( foreach (var lineGroup in lineGroups) { var lineCharIndexes = lineGroup.ToList(); - var rect = CalculateBoundingRect(lineCharIndexes, textInfo, transform); + var rect = CalculateBoundingRect(lineCharIndexes, textInfo); if (rect.HasValue) rects.Add(rect.Value); } @@ -451,21 +449,20 @@ private static List CalculateLineBoundingRects( /// private static Rect? CalculateBoundingRect( List charIndexes, - TMP_TextInfo textInfo, - Transform transform) + TMP_TextInfo textInfo) { if (charIndexes == null || charIndexes.Count == 0) return null; var firstCharInfo = textInfo.characterInfo[charIndexes[0]]; - var bottomLeft = transform.TransformPoint(firstCharInfo.bottomLeft); - var topRight = transform.TransformPoint(firstCharInfo.topRight); + var bottomLeft = (Vector2)firstCharInfo.bottomLeft; + var topRight = (Vector2)firstCharInfo.topRight; foreach (var index in charIndexes.Skip(1)) { var charInfo = textInfo.characterInfo[index]; - var charBottomLeft = transform.TransformPoint(charInfo.bottomLeft); - var charTopRight = transform.TransformPoint(charInfo.topRight); + var charBottomLeft = (Vector2)charInfo.bottomLeft; + var charTopRight = (Vector2)charInfo.topRight; bottomLeft = Vector2.Min(bottomLeft, charBottomLeft); topRight = Vector2.Max(topRight, charTopRight); diff --git a/Runtime/Helper/TextMeshProExtensions.cs.meta b/Runtime/Helper/TextMeshProExtensions.cs.meta index edf8133..b126bc3 100644 --- a/Runtime/Helper/TextMeshProExtensions.cs.meta +++ b/Runtime/Helper/TextMeshProExtensions.cs.meta @@ -1,2 +1,11 @@ fileFormatVersion: 2 -guid: 20280a4e092591642b49ee40bf4bd7d3 \ No newline at end of file +guid: 20280a4e092591642b49ee40bf4bd7d3 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/package.json b/package.json index c91a90f..f5d13fe 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "com.kwanjoong.textmeshpromax", - "version": "0.5.2", + "version": "0.6.0", "displayName": "Text Mesh Pro Max", "description": "The ultimate Text Mesh Pro helper package.", "unity": "2022.3",