Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

TextMesh Pro Text Mesh Pro Font Asset Creation via Editor Script

Discussion in 'UGUI & TextMesh Pro' started by Mimimi_Jonas, Aug 2, 2017.

  1. Mimimi_Jonas

    Mimimi_Jonas

    Joined:
    Aug 2, 2017
    Posts:
    2
    Hi there,

    I just evaluated the Text Mesh Pro plugin from the Asset Store for our company and stumbled across one major problem.
    In our last project we used uGUI and for Consoles we used a merged font with all korean,chinese, japanese characters.
    In our build pipeline the font file was then stripped only leaving the characters used by the localization files.

    So when rewriting our system to Text Mesh Pro we would need to do similar.
    I saw that you could do all of the above mentioned manually, but there is currently no public method in the editor classes, that allow to do the exact procedere via code.
    We would have to:
    1. Set the font and the generation parameters (Pass in the string of used Characters to Custom Characters field)
    2. generate the font
    3. overwrite the old font file
    4. receive some kind of callback so we know we can go on with the building process
    Am I missing something crucial here or is this a thing we might be seeing in the future?

    Regards,
    Jonas
     
  2. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    When not simply pre-generate those Font Assets using the "Characters from File" to include the characters used for localization? Why merge or alter the current assets? At build time, you would simply switch to using those alternative font assets and fallbacks for those given languages.

    Most TextMesh Pro users dealing with localization will generate Primary font assets which only contains the known characters used in the project broken up by language groups. The use language files as a source in conjunction with the "Characters from File" option in the Font Asset Creator.

    Typically, they will have a Latin Primary Font Asset which could include a fallback for Cyrillic.

    For Chinese, Japanese and Korean, they will have a Primary font asset which again only contains the characters used in the project. If the project includes user input then they will have a few fallback font assets for each of those languages.

    Most of the time, their Latin based Primary font asset includes a few Chinese, Japanese and Korean characters just to be able to display the menu items / buttons used for selecting those languages. The same is true for their Chinese, Japanese and Korean.

    In some cases, users either include all those font assets in the build and switch font asset depending on language selection or only include the Latin set and use Asset Bundles to load the other language sets when needed.

    Having said all of that and I have not looked into this in a long while, I do have users who have created their own script to create font assets via scripting. Here is a link to one such post from the TMP user forum. The font asset creation process is an editor only process and not run time.
     
  3. Mimimi_Jonas

    Mimimi_Jonas

    Joined:
    Aug 2, 2017
    Posts:
    2
    Thanks for the quick response.
    This is exactly what I want to do, but automated via script. We can throw in our files there but I still wouldn't want to do that manually for every build, especially in the phase where our loca files (and thus the needed characters in the fonts) are changing all the time.

    All the code is already in the DLL but it would be nice if you exposed the API calls there.

    Of course we only need this in Editor, not during runtime, is this possible?
    I am thinking of a function like this:
    TMP_FontAssetCreatorWindow.createFontAsset(Font _font, Resolution _res, string _customCharactersFilePath, string _createFontAssetAtPath, ...)

    It would be nice if we got something like this for a later Build, I guess for now I will go with the solution provided in the link, which seems like a good workaround for now.
     
  4. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Most of the API should be exposed although whatever might have been missing in the past, given those users all had / have access to the source code, I presume they would have modified whatever was needed.

    I suggest you take a look at what is already exposed (which I unfortunately never really documented with regards to the font asset creation / API) and let me know if you run into anything that appears to be missing or an issue to achieve what you need.
     
  5. unity-dev

    unity-dev

    Joined:
    May 15, 2016
    Posts:
    10
    @Jonas_J Any luck with that?

    @Stephan_B Any chance you could briefly explain how to access the required API? I can't find any of the types found in the post you linked. Thanks.
     
  6. unity-dev

    unity-dev

    Joined:
    May 15, 2016
    Posts:
    10
    No info at all?
     
  7. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    The last post in that thread contains a link Github which includes a script used to back font assets.

    The script is called TMPFontAssetBaker.cs. and should contain the information necessary to implement or at least learn how this was implemented by this TextMesh Pro user.
     
  8. unity-dev

    unity-dev

    Joined:
    May 15, 2016
    Posts:
    10