Author Topic: Dynamic Fonts v2.6.0  (Read 25240 times)

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: Dynamic Fonts v2.6.0
« Reply #30 on: April 29, 2013, 08:52:43 AM »
When the characters exceed the font texture size, the font texture size is resized and I think all labels need to refresh at that point, since the texture coordinates for each character then change. I'm not sure the 2.6.0 version does this, but I haven't dug into it yet.

Ferazel

  • Full Member
  • ***
  • Thank You
  • -Given: 1
  • -Receive: 2
  • Posts: 150
    • View Profile
Re: Dynamic Fonts v2.6.0
« Reply #31 on: April 29, 2013, 11:18:38 AM »
Yeah, I don't have 2.6 yet (standard license). From my understanding of dynamic fonts, an element in NGUI needs to be responsible for updating all of the UILabel's texture coordinates when Font.textureRebuildCallback is called by the UnityEngine.Font object. The problem is that every UILabel can't register for this as it is a delegate instead of an event. So maybe the UIFont, if set to be a dynamic font, will dispatch it's own event that the UILabels will listen if they use the dynamic font? (just a suggestion)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Dynamic Fonts v2.6.0
« Reply #32 on: April 29, 2013, 05:48:44 PM »
Try this... in UIFont, add the following function:
  1. void OnFontChanged ()
  2. {
  3.         UILabel[] labels = Object.FindObjectsOfType(typeof(UILabel)) as UILabel[];
  4.  
  5.         for (int i = 0, imax = labels.Length; i < imax; ++i)
  6.         {
  7.                 UILabel lbl = labels[i];
  8.                 if (lbl.font == this) lbl.MarkAsChanged();
  9.         }
  10. }
Then change UIFont's Print() function, changing this line (inside #if !UNITY_3_5 block):
  1. if (dynamic) mDynamicFont.RequestCharactersInTexture(text, mDynamicFontSize, mDynamicFontStyle);
to this:
  1. if (dynamic)
  2. {
  3.         mDynamicFont.textureRebuildCallback = OnFontChanged;
  4.         mDynamicFont.RequestCharactersInTexture(text, mDynamicFontSize, mDynamicFontStyle);
  5.         mDynamicFont.textureRebuildCallback = null;
  6. }
« Last Edit: April 29, 2013, 05:55:44 PM by ArenMook »

dlewis

  • Guest
Re: Dynamic Fonts v2.6.0
« Reply #33 on: April 29, 2013, 06:10:30 PM »
If what ArenMook suggested doesn't work, create an example project/scene and post it.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Dynamic Fonts v2.6.0
« Reply #34 on: April 29, 2013, 06:12:11 PM »
Careful posting example scenes. If you post an example, make sure NGUI source isn't a part of it.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Dynamic Fonts v2.6.0
« Reply #35 on: May 02, 2013, 08:40:14 AM »
Soo... did my snipplet fix the issue? I need to know whether to add this change to the repository for 2.6.1 or not.

jeldrez

  • Sr. Member
  • ****
  • Thank You
  • -Given: 8
  • -Receive: 4
  • Posts: 352
    • View Profile
Re: Dynamic Fonts v2.6.0
« Reply #36 on: May 02, 2013, 09:34:39 AM »
Sorry, I'll try it tonight and let you know how it was.

jeldrez

  • Sr. Member
  • ****
  • Thank You
  • -Given: 8
  • -Receive: 4
  • Posts: 352
    • View Profile
Re: Dynamic Fonts v2.6.0
« Reply #37 on: May 03, 2013, 12:38:14 AM »
It didn't work.

I created a scene with a dynamic font.
Then I did a Label and duplicated.
Finally I did a script keybinding some keys with different texts and the text got corrupted with Q and W key, but got fixed with R.

-UIRoot
--UICamera
---UIAnchor
----UIPanel
-----UILabel 1 <text = UNO> (This label has the script)
-----UILabel 2 <text = DOS> (This label get corrupted)

The font texture was 256x256 px.

  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4.  
  5. public class SRC_DynamicFontTest : MonoBehaviour
  6. {
  7.    void Update ()
  8.    {
  9.       if (Input.GetKeyDown(KeyCode.Q))
  10.         {
  11.             UILabel lbl = GetComponent<UILabel>();
  12.             lbl.text = "@$$^34567784561!!!!!!!!!/lkasjflkajsdlñfkj lñaksfj lkasdf lkasdjflkñvjkKLLÑKSDJLKFJLÑKSJDFLKÑJSDDFLÑKJ";
  13.         }
  14.       if (Input.GetKeyDown(KeyCode.W))
  15.         {
  16.             UILabel lbl = GetComponent<UILabel>();
  17.             lbl.text = "12345566778899000";
  18.         }
  19.       if (Input.GetKeyDown(KeyCode.E))
  20.         {
  21.             UILabel lbl = GetComponent<UILabel>();
  22.             lbl.text = ")O()=?#($()#?=KJASLKÑDJÑLKASJDÑLKASJD,mv,mv";
  23.         }
  24.       if (Input.GetKeyDown(KeyCode.R))
  25.         {
  26.             UILabel lbl = GetComponent<UILabel>();
  27.             lbl.text = "ABCDEFGHIJKLMNÑOPQRSTUVWXYZ!#$%%&&/(()=?'-_:;,M<>";
  28.         }
  29.    }
  30. }
  31.  

dlewis

  • Guest
Re: Dynamic Fonts v2.6.0
« Reply #38 on: May 03, 2013, 01:29:59 AM »
Careful posting example scenes. If you post an example, make sure NGUI source isn't a part of it.

An asset bundle which contains just the scene and associated test script would work best. No NGUI source and contains the example.

maoguo.zhang

  • Guest
Re: Dynamic Fonts v2.6.0
« Reply #39 on: May 03, 2013, 03:17:35 AM »
Hello! I've tested dynamic font of v2.6.0. It is wonderful and very useful to our project.
For some reason, I must use two different shaders for two dynamic fonts in our project. So I writte another shader and create a different material. I found changing the material of the dynamic font was not allowed.

Could you give me some advice? :)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Dynamic Fonts v2.6.0
« Reply #40 on: May 03, 2013, 11:19:45 AM »
@jeldrez: thanks, that code helped. 2.6.1 has the fix.

@maoguo.zhang: Why not? You can change it on the UIFont prefab.

jeldrez

  • Sr. Member
  • ****
  • Thank You
  • -Given: 8
  • -Receive: 4
  • Posts: 352
    • View Profile
Re: Dynamic Fonts v2.6.0
« Reply #41 on: May 03, 2013, 01:06:11 PM »
Thanks Aren.
I will try new version ASAP.

maoguo.zhang

  • Guest
Re: Dynamic Fonts v2.6.0
« Reply #42 on: May 05, 2013, 11:06:10 PM »

@maoguo.zhang: Why not? You can change it on the UIFont prefab.

I've tried this many times and I believe that my approach is right. My Unity is V4.1.2.


UIFont.cs
if (isDynamic)
{
   if (mMat != null) mMat.mainTexture = mDynamicFont.material.mainTexture;
   return mDynamicFont.material;
}

I haven't found where you assign mDynamicFont.material.

realblues

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 28
    • View Profile
Re: Dynamic Fonts v2.6.0
« Reply #43 on: May 06, 2013, 12:19:02 AM »
I just updated 2.6.1, thanks for lot of work :)

UI Label Works fine. but when I Created UIInput, looks working only Alphabetic Language input while runtime.

is it?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Dynamic Fonts v2.6.0
« Reply #44 on: May 06, 2013, 01:47:37 AM »
Dynamic font only changes the visualization of the font, so if input doesn't work with it for some reason, chances are standard font won't work either. Does it? Make sure the TTF you chosen actually has the glyphs. Most fonts don't have asian glyphs in them.