Unity How do I Flow TextMesh Pro Text around an Image?
Asked Answered
L

1

10

Unity Version: 5.6.5f1 Personal

TextMesh Pro Version: 1.0.56.0b3

I have a TextMesh Pro UI Text object whose area intersects the area of a UI Image. The text is dynamic, but the image will never change. Is there a way to make the TextMesh Pro UI Text flow around the image similar to how text would wrap to one side in HTML/CSS?

The image below shows two copies of the object in Unity. One object, denoted by a red space where the image is located, is what I'm currently getting. The text enters the space of the image. The other object, denoted by a blue space where the image is located, shows the desired outcome where text is wrapping properly.

Current vs. Desired Outcome: Current vs. Desired Outcome

Research so far:

How do I put an image inside text? - The Image that I'm using is a UI Image, not a text asset. The Image will only act as though it is inline with the text.

How do you wrap text around a rectangle?, Fluid layout for Unity UI - These are what I'm looking for. However, no suggestions have been posted in them.

I've explored the idea of using multiple TextMesh Pro UI Text Objects, with each one acting as a fragment of the complete text area. However, this isn't the same as wrapping the text around the Image. For dynamic text, if I pull content from one text area and push it into the next area, this will conflict with the Auto-Sizing functionality and cause unequal font sizes.

Another possibility is that I could insert characters one at a time, check to see if adding another character would result in a collision with the image, and add System.Environment.Newline to prevent this. However, I worry about the potential performance issues from dealing with large amounts of text.

TextMesh Pro Documentation - The TextMesh Pro Documentation has some tools for finding word wrap points, but I haven't figured out how to implement a means of comparing this to an anchor position of another object.

Lumbye answered 23/3, 2018 at 8:34 Comment(4)
Do you find the solution ?Tactless
Sadly, no. I've been playing around with the idea of defining an explicit space where text should not be allowed as variables in a script. However, by trying to do this, the text would be refactored. If the text was already filling a container, then there exists the possibility of overflow. Decisions, decisions.Lumbye
Any luck finding a solution?Hardspun
Hey, @AndrewPullins. Unfortunately, no. I haven't revisited this question in a while. Real life stuff.Lumbye
I
8

enter image description hereThis can be accomplished with TextMeshPro's "Linked" overflow mode. See attached picture for an example. Essentially, you'll need to make two TMP objects and adjust the layout for each of them appropriately. Then:

1) change the overflow mode of the first one to "Linked" using the dropdown in the inspector.

2) place the second TMP object as the reference in the field that appears.

Impost answered 27/1, 2020 at 20:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.