Author Topic: Dynamic Font change on the fly  (Read 7753 times)

Clicker

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 16
    • View Profile
Dynamic Font change on the fly
« 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.

MrTact

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 2
  • Posts: 32
    • View Profile
Re: Dynamic Font change on the fly
« Reply #1 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.

Clicker

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 16
    • View Profile
Re: Dynamic Font change on the fly
« Reply #2 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.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Dynamic Font change on the fly
« Reply #3 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.

PoN

  • Full Member
  • ***
  • Thank You
  • -Given: 1
  • -Receive: 4
  • Posts: 111
    • View Profile
Re: Dynamic Font change on the fly
« Reply #4 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.
Worked on Doc&DogAge Of Fury 3D. Actually working on WarMach.

Clicker

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 16
    • View Profile
Re: Dynamic Font change on the fly
« Reply #5 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 :) ).

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Dynamic Font change on the fly
« Reply #6 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.