Search Unity

  1. Looking for a job or to hire someone for a project? Check out the re-opened job forums.
    Dismiss Notice
  2. Unity 2020 LTS & Unity 2021.1 have been released.
    Dismiss Notice
  3. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

TextMesh Pro Drawing an Image over a line of text

Discussion in 'UGUI & TextMesh Pro' started by MrHappyKiller, Jul 23, 2017.

  1. MrHappyKiller

    MrHappyKiller

    Joined:
    Feb 8, 2016
    Posts:
    29
    I'm currently using the link system in TMP to organize my separate save files (Thank you Stephan), but I'm having a whole lot of trouble with this one aspect. I'm wanting to draw a simple Image piece (I just set it as active when needed) over the text line to act as a suggestion box. I got this to slightly work. But my problem was, as I went down the lines, the box would go a little bit above the line each time. So basically, when I was at the bottom the box would be three lines above. Here's what I mean:

    http://imgur.com/a/5bEZZ

    As you can see, kinda weird what it's doing. I originally thought I could put the image outside the canvas perhaps and transform a point, but this did not work.
     
  2. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    5,625
    Again take a look at the TextInfoDebugTool.cs script and how it draws the bounds for individual lines.
     
  3. MrHappyKiller

    MrHappyKiller

    Joined:
    Feb 8, 2016
    Posts:
    29
    I did, but even when transforming the point as shown in the debug, I get that same problem:

    Code (CSharp):
    1.         if (GetCurrentLinkIndex() > -1)
    2.         {
    3.             var lineInfo = saveText.textInfo.lineInfo[GetCurrentLinkIndex()];
    4.             var textInfo = saveText.textInfo;
    5.  
    6.             float ascender = lineInfo.ascender;
    7.             float descender = lineInfo.descender;
    8.  
    9.             Vector3 bottomLeft = saveText.transform.TransformPoint(new Vector3(textInfo.characterInfo[lineInfo.firstCharacterIndex].bottomLeft.x, descender, 0));
    10.             Vector3 topLeft = saveText.transform.TransformPoint(new Vector3(textInfo.characterInfo[lineInfo.firstCharacterIndex].bottomLeft.x, ascender, 0));
    11.             Vector3 topRight = saveText.transform.TransformPoint(new Vector3(textInfo.characterInfo[lineInfo.lastCharacterIndex].topRight.x, ascender, 0));
    12.             Vector3 bottomRight = saveText.transform.TransformPoint(new Vector3(textInfo.characterInfo[lineInfo.lastCharacterIndex].topRight.x, descender, 0));
    13.  
    14.             LoadSelectionArrow(true, topLeft.x, topLeft.y);
    15.         }
    Maybe I'm not seeing something I should, I seem to be terrible at this
     
  4. MrHappyKiller

    MrHappyKiller

    Joined:
    Feb 8, 2016
    Posts:
    29
    Well, silly me. The problem was within my code. When loading it, I was drawing it based on a weird set of wrong local coords. Used a line renderer to draw the image and it works like a charm. :) Thanks! You seem to be the most helpful developer on here.
     
unityunity