Author Topic: Dynamic Font package for NGUI 2.5.1 (for unity 4.x)  (Read 38344 times)

DarkMagicCK

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 20
    • View Profile
Dynamic Font package for NGUI 2.5.1 (for unity 4.x)
« on: April 08, 2013, 02:51:58 AM »
Hello guys, I spent some hours to merge most of the great works done by great people in the top thread, and made a merge package for NGUI 2.5.1.
Here's some merge node:
1. UIFont and UIFontInspector dynamic font support from @Unisip.
2. yOffset logic and inspector support from @zh4ox and @Mudwiz.
3. Support clipping, Clip shaders from great @Nicki. As hard clip is not suggested, use alpha clip instead.

As dynamic fonts are only avaliable in unity 4.x, this package does not support 3.x.
How to use this package to setup dynamic fonts:
1. Import font ttf file and set font size to 1.
2. Create a new gameobject, attach a UIFont script and make this a prefab.
3. Adjust prefab inspector values.
   
    Font Type: Choose DYNAMIC.
    Font: Drag your ttf file into this slot.
    Material: You need to create a new material with "Unlit/Dynamic Text Shader" for each different font, same font with different size can use same material.
    Size: the font size you want.
    TTF Size: size of the ttf import setting, as this situation, set it to 1.
    Const Offset: default the text's y offset is not correct(still no solution yet), and this value can be different for different fonts. You can adjust this value to fit the texts in box, other sizes of the same font will mostly be correct.
4. Create UILabel using this prefab as UIFont and that's it.
« Last Edit: April 10, 2013, 03:04:28 AM by DarkMagicCK »

tkok

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 16
    • View Profile
Re: Dynamic Font for NGUI 2.5.1
« Reply #1 on: April 08, 2013, 03:22:18 AM »
I tried to import NGUI_2.5.1_DynamicFont.unitypackage -package and I only got an error:
Quote
"Fatal error!
type == kMetaAssetType && pathName.find ("library/metadata") != 0"

And then unity crashes.

System: Mac os x 10.7.5
Unity: 3.5.7f6

I fastly tried it with my windows pc and it did give me same error.

DarkMagicCK

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 20
    • View Profile
Re: Dynamic Font for NGUI 2.5.1
« Reply #2 on: April 08, 2013, 03:26:08 AM »
I tried to import NGUI_2.5.1_DynamicFont.unitypackage -package and I only got an error:
"Fatal error!
type == kMetaAssetType && pathName.find ("library/metadata") != 0"
And then unity crashes.

System: Mac os x 10.7.5
Unity: 3.5.7f6

I fastly tried it with my windows pc and it did give me same error.

NGUI 2.5.1 only support unity 4.0+, so this package is for unity 4.0+

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: Dynamic Font package for NGUI 2.5.1 (for unity 4.x)
« Reply #3 on: April 08, 2013, 05:15:48 AM »
Cool package.
A note though - NGUI 2.5.1 supports Unity 3.5.5 and up, but dynamic fonts only work in Unity4 (at least for mobile).

pretender

  • Full Member
  • ***
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 155
    • View Profile
Re: Dynamic Font package for NGUI 2.5.1 (for unity 4.x)
« Reply #4 on: April 08, 2013, 05:16:09 AM »
In release notes it does not say that ngui is unity 4+ only but 3.5+ (but dynamic font is unity4+ only feature)

DarkMagicCK

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 20
    • View Profile
Re: Dynamic Font package for NGUI 2.5.1 (for unity 4.x)
« Reply #5 on: April 08, 2013, 06:46:59 AM »
Cool package.
A note though - NGUI 2.5.1 supports Unity 3.5.5 and up, but dynamic fonts only work in Unity4 (at least for mobile).
lol thanks, I've changed the note.

jeldrez

  • Sr. Member
  • ****
  • Thank You
  • -Given: 8
  • -Receive: 4
  • Posts: 352
    • View Profile
Re: Dynamic Font package for NGUI 2.5.1 (for unity 4.x)
« Reply #6 on: April 08, 2013, 09:36:13 AM »
Thanks DarkMagic!
a solution until v.2.6.0 is coming.

agrignon

  • Guest
Re: Dynamic Font package for NGUI 2.5.1 (for unity 4.x)
« Reply #7 on: April 08, 2013, 04:31:45 PM »
Thx! Just gave this a shot, and seem to hit a problem with > 1 font. The most recently edited font works fine, while the other dynamic fonts get corrupted. In my case I'm using 3 typefaces, and whatever I edit most recently (ie, just changing the style from Normal to Bold in the panel) will look correct while the other fonts show up as gibberish.


DarkMagicCK

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 20
    • View Profile
Re: Dynamic Font package for NGUI 2.5.1 (for unity 4.x)
« Reply #8 on: April 08, 2013, 10:18:33 PM »
Thx! Just gave this a shot, and seem to hit a problem with > 1 font. The most recently edited font works fine, while the other dynamic fonts get corrupted. In my case I'm using 3 typefaces, and whatever I edit most recently (ie, just changing the style from Normal to Bold in the panel) will look correct while the other fonts show up as gibberish.
You need to setup new material for new fonts, I just made one default Material in NGUI/Resources/Material.
Create material with shader Unlit/Dynamic Text Shader anywhere, and put this into new font's prefab.

jeldrez

  • Sr. Member
  • ****
  • Thank You
  • -Given: 8
  • -Receive: 4
  • Posts: 352
    • View Profile
Re: Dynamic Font package for NGUI 2.5.1 (for unity 4.x)
« Reply #9 on: April 08, 2013, 10:27:51 PM »
yeps, it happens to me before. You need to check the font material.

huixiong

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 6
    • View Profile
Re: Dynamic Font package for NGUI 2.5.1 (for unity 4.x)
« Reply #10 on: April 09, 2013, 02:57:56 AM »
some time, i meant this solution:in phone, some of the world cannot be printed.
Maybe When UIFont callback OnFontRebuilt() function,some labels were not be repaint in cellphone android environment.
Can you help me ?
ps:
   font.dynamicFont.textureRebuildCallback += OnFontRebuilt;
« Last Edit: April 09, 2013, 07:47:59 AM by huixiong »

jarjin

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 28
    • View Profile
Re: Dynamic Font package for NGUI 2.5.1 (for unity 4.x)
« Reply #11 on: April 09, 2013, 04:12:15 AM »
Thanks DarkMagic!
a solution until v.2.6.0 is coming.
+1

agrignon

  • Guest
Re: Dynamic Font package for NGUI 2.5.1 (for unity 4.x)
« Reply #12 on: April 09, 2013, 11:17:24 AM »
You need to setup new material for new fonts, I just made one default Material in NGUI/Resources/Material.
Create material with shader Unlit/Dynamic Text Shader anywhere, and put this into new font's prefab.

Perfect - working now, thanks!

Groszq

  • Guest
Re: Dynamic Font package for NGUI 2.5.1 (for unity 4.x)
« Reply #13 on: April 09, 2013, 11:56:42 AM »
Do I have to create new materials for new fonts, because I met with opposite solutions?

agrignon

  • Guest
Re: Dynamic Font package for NGUI 2.5.1 (for unity 4.x)
« Reply #14 on: April 09, 2013, 05:34:32 PM »
You need to setup new material for new fonts, I just made one default Material in NGUI/Resources/Material.
Create material with shader Unlit/Dynamic Text Shader anywhere, and put this into new font's prefab.

One more thing... in looking at the output from my previous screenshot, you'll see the baseline of the font seems off making look a bit like a ransom note. When I used this previously with BMFont (with only using the 'recommended' settings for NGUI) it looked correct. Do you know if there something else I can tweak to make this more even?