Search Unity

TextMesh Pro, Selectable Whitespace

Discussion in 'UGUI & TextMesh Pro' started by Sachs3n, Nov 30, 2018.

  1. Sachs3n

    Sachs3n

    Joined:
    Aug 24, 2014
    Posts:
    4
    I'm using a modified version of TMP_TextEventCheck and TMP_TextEventHandler. I want to be able to select whitespace in the text. Looking at example 12a Text Interactions, it appears that this sample does not allow the user to select whitespace.

    Is there anything I'm missing, or do I need to roll my own to allow whitespace to be selectable?
     
  2. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    If you take a look at the TMP_TextEventHandler.cs script at line 128, you will see the following:

    Code (csharp):
    1.  
    2. int charIndex = TMP_TextUtilities.FindIntersectingCharacter(m_TextComponent, Input.mousePosition, m_Camera, true);
    3.  
    This function has the following signature:

    public static int FindIntersectingCharacter(TMP_Text text, Vector3 position, Camera camera, bool visibleOnly)

    Setting visibleOnly to false will then also check for non-visible / whitespace characters.
     
  3. Sachs3n

    Sachs3n

    Joined:
    Aug 24, 2014
    Posts:
    4
    That's amazing. Exactly what I needed. Thanks so much.