Support for custom fonts in XML UI.
I think the most straight-forward implementation would be to extend CustomAssetState
to have a (nullable) string type
field, which for backward compatibility defaults to ‘image’.
We could have type ‘font’. However, that’s a pain as users are likely going to expect standard font file formats (ttf, otf etc.) to work. Where as most likely only TextMeshPro SDFs would be acceptable, and getting those as standalone files is not easy. So, it’s probably a lot easier just to have type ‘bundle’, as in asset bundle.
Then TTS can load all the resources (or all the ones you want to support) in the bundle and register those resources with XmlLayout. Whilst fonts are name of the game here, if expanded upon, there’s some other nice wins to be had e.g. sprite assets where we can specify the rects/bounds such 9-slice UIs work, and so forth.
Since Unity acquired TextMeshPro, I’m not sure how tight the integration is - may need to explictly load the SDF into a dynamic TMP asset. Fortunately, XmlLayout already has support for TextMeshPro (https://www.digital-legacy.co.za/XmlLayout/Documentation#TextMeshPro), so for us users, it ought to be pretty straight forward as long as we can reference the fonts somehow.
Ohh, and have the fonts support translation tags. Translations sometimes are longer so could use arial narrow, while the shorter ones have arial for example.
Any update on this?
This is awesome. Has this already been released? Can you link to the documentation that explains how to do this?
I would also be interested. I HATE the UI default font T.T
Can we get a documentation update for this? No one seems to be able to explain how to use it.
Basic howto:
In unity import the fonts you need and create a asset bundle for them
In the UI configuration add an elements, and reference the asset bundle.
In the xml for the ui set the font element to font=”imported element/full font name”
I got it working for my project doing this.
Erikmum, is your project on the workshop? I’m keen to see how you utilised this.
Is there any documentation on how to make these font custom assetsbundles and how to reference them?