Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: Clicker on April 01, 2014, 12:05:32 PM

Title: Dynamic Font change on the fly
Post by: Clicker on April 01, 2014, 12:05:32 PM
Hello. We have been working on a project where a custom localization system is being used. So, there is a need of changing the actual font in every single label depending on language. Hence, we keep a reference on a UIFont prefab as reference to a UIFont prefab with dynamic font, and in runtime we just change the replacement reference to another UIFont prefab. While doing so, sometimes some labels seem to lose correct UVs for each char, but if we reenable those labels - the issue is gone. Anyway, it is not a good solution for the issue and it would be very helpfull if you know how to avoid it.

Here is a screenshot http://clip2net.com/s/78qXC9 (http://clip2net.com/s/78qXC9).
Title: Re: Dynamic Font change on the fly
Post by: MrTact on April 01, 2014, 02:33:28 PM
We did something very similar to this, except that we used dynamic fonts. This worked pretty seamlessly for us. If using dynamic fonts is an option for you, I can state with confidence that that works.
Title: Re: Dynamic Font change on the fly
Post by: Clicker on April 02, 2014, 02:12:41 AM
Well, actually, we do use only dynamic fonts in our project. This problem appears not only in editor but on devices as well.
Title: Re: Dynamic Font change on the fly
Post by: ArenMook on April 02, 2014, 04:03:54 PM
"we keep a reference on a UIFont prefab as reference to a UIFont prefab with dynamic font"

Not quite clear on that one.

If you have a reference font pointing to another font prefab that you change at run-time, then everything should work fine. However... there may be an issue related to when you swap the font. If it's between Start() calls for example. You need to make sure that you do the font swap first when loading the scene -- in Awake(), before everything else.
Title: Re: Dynamic Font change on the fly
Post by: PoN on April 03, 2014, 03:01:24 AM
we have same trouble of dynamic fonts, just when open/close (enable/disable gameobject  with UIPanel) windows, but that appear only one time in game session.
Title: Re: Dynamic Font change on the fly
Post by: Clicker on April 05, 2014, 04:30:31 AM
"we keep a reference on a UIFont prefab as reference to a UIFont prefab with dynamic font"

Not quite clear on that one.

If you have a reference font pointing to another font prefab that you change at run-time, then everything should work fine. However... there may be an issue related to when you swap the font. If it's between Start() calls for example. You need to make sure that you do the font swap first when loading the scene -- in Awake(), before everything else.
Exactly, that is the pointer as you described how to workout the font change in runtime, but we have a switcher for languages in option menu, so, we have to change language on the fly.
we have same trouble of dynamic fonts, just when open/close (enable/disable gameobject  with UIPanel) windows, but that appear only one time in game session.
Confirm. We have the same.

The only fine solution I have found is to update all label in the visible panels, just by changing the text to empty and again to the previous one (kind of hack, I know :) ).
Title: Re: Dynamic Font change on the fly
Post by: ArenMook on April 05, 2014, 11:44:22 AM
Can't you just broadcast "MarkAsChanged"? UILabels have this function that effectively forces everything to be rebuilt.