Search Unity

TextMesh Pro Previewing a TextMeshPro in an EditorWindow

Discussion in 'UGUI & TextMesh Pro' started by Spidyy, Aug 25, 2017.

  1. Spidyy

    Spidyy

    Joined:
    Mar 6, 2011
    Posts:
    184
    Hello there !

    I could have posted it in the Editor Extension section, but I think someone who used UnityUI and TextMeshPro will have a better idea. :)

    I'm writing a tool to have a centralised database of all the TextMeshPro styles used in a project, and to avoid the users to stray across the different scenes to see the result of each change they are doing, I'd like to render a kind of preview window directly in the tool.

    The issue is, I quite have an idea on how to do it.

    The best idea I had is to have a hidden camera (like the scene view camera), a hidden canvas and one hidden TextMeshPro object, all the the same culling layer, but I couldn't get the TextMeshPro to render yet and I don't want to use one of the few culling layers we have, nor have the user to configure each of its cameras to not display the used layer.

    Do anyone successfully rendered a TextMeshPro in an EditorWindow without having too much to sacrifice?

    Spidyy
     
  2. Spidyy

    Spidyy

    Joined:
    Mar 6, 2011
    Posts:
    184
    After some try out, I figured the simplest was :
    - Create a Camera, Canvas and TextMeshProUGUI objects.
    - Set their flags as HideAndDontSave
    - Properly setup their parenting and give them the same layer. Have the camera to display only this layer. Deactivate their game objects after creation.
    - When in the OnGUI function, active them, and use Handles.DrawCamera(rect, yourCamera), then deactivate them again.

    If the camera is correctly positioned, it draws the TextMeshPro in the rect area specified to DrawCamera.
     
    jiraphatK likes this.