Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: jeldrez on April 20, 2013, 10:27:43 AM

Title: Dynamic Fonts v2.6.0
Post by: jeldrez on April 20, 2013, 10:27:43 AM
I just update to the latest version and continue having issues with dynamic fonts.


1] I created and empty gameobject (with reset values), drag and drop UIFont.cs into it.
2] Set Font Type to Dynamic
3] Drag and drop the TTF, set the scale. (I can't set the material, it use the TTF one)


Until then everything is ok, but in game, sometimes looks corrupt (image attached).


There's another way to create Dynamic Font?


Thanks!
Title: Re: Dynamic Fonts v2.6.0
Post by: dlewis on April 20, 2013, 06:21:30 PM
I find that happens (in another dynamic font package I use) when the texture gets rebuilt. When that happens, every label needs to rebuild it's geometry/update it's uv's, looks like the same issue here.
Title: Re: Dynamic Fonts v2.6.0
Post by: ArenMook on April 21, 2013, 07:21:34 PM
Why are you creating a game object and putting UIFont on it? Use the Font Maker.
Title: Re: Dynamic Fonts v2.6.0
Post by: jeldrez on April 22, 2013, 07:43:08 AM
Why are you creating a game object and putting UIFont on it? Use the Font Maker.
In the Font Maker I just see texture font option. Asking for Font Data (.txt) and the Texture.
How I create a dynamic font from there? I was using the old way with empty gameobjects.



Title: Re: Dynamic Fonts v2.6.0
Post by: ArenMook on April 22, 2013, 01:42:38 PM
If you don't see dynamic font creation option then you don't have 2.6.0.
Title: Re: Dynamic Fonts v2.6.0
Post by: jeldrez on April 22, 2013, 02:08:27 PM
The package it says 2.6.0, even the readme.txt file it has 2.6.0 on it.
So, I supposed it was the last version.
Title: Re: Dynamic Fonts v2.6.0
Post by: ArenMook on April 22, 2013, 04:43:49 PM
What package? Pro doesn't come in package form. Pull the latest changes from the repository.
Title: Re: Dynamic Fonts v2.6.0
Post by: jeldrez on April 22, 2013, 05:15:39 PM
What package? Pro doesn't come in package form. Pull the latest changes from the repository.
I got the zip file (ArenMook-ngui-b03b43981ccb.zip) from the repository last Saturday.
I should get a new version?

Title: Re: Dynamic Fonts v2.6.0
Post by: ArenMook on April 22, 2013, 05:26:37 PM
Commit da2dc78:
https://bitbucket.org/ArenMook/ngui/commits/da2dc78261bd99b3beef1f5f5341adfd356a5317
Quote
- FIX: Font Maker now supports creation of dynamic fonts.
Title: Re: Dynamic Fonts v2.6.0
Post by: jeldrez on April 23, 2013, 08:01:20 AM
Thank you!
I'm going to try it now.
Title: Re: Dynamic Fonts v2.6.0
Post by: jeldrez on April 23, 2013, 04:53:16 PM
Nice, it's working!
There's a way to replace my old fonts? because change hand by hand each label it's a lot of work.

Title: Re: Dynamic Fonts v2.6.0
Post by: agrignon on April 24, 2013, 05:58:36 AM
I've updated to 2.6 and recreated my dynamic fonts with the font maker. I have 3 typefaces, and in the sim all works perfectly. When I build and deploy on device (iPad HD w/thunderbolt) however, I only get one of them showing up - it's always the same one. The others don't show gibberish, they're just empty. Any suggestions?
Title: Re: Dynamic Fonts v2.6.0
Post by: jeldrez on April 24, 2013, 08:04:10 AM
Did you check the Z depth?  sometimes you need to move it closer to the camera. Somehow it works only moving 1 text closer (Z = -10).
At least that works for me, but I need to chaaaange aaaaall the text in game now... well, at least the upgrade worth it.
Title: Re: Dynamic Fonts v2.6.0
Post by: jeldrez on April 24, 2013, 09:25:52 AM
I continue having corrupt text in game.
I just deleted the old dynamic fonts and created new ones. I put the new ones in each Label an in the Scene looks great, but playing the game and changing menus the text corrupts and looks like the image attached in the first post.

Also, like Agrignon sometimes the text dissapear, like randomly.

Aren we need your help, please!

PS: another thing it's \n is not working in the UILabel area text, now it recognize it like plain text.


PS2: This could be a material problem? what about let people change the material? now it doesn't.
Title: Re: Dynamic Fonts v2.6.0
Post by: ArenMook on April 24, 2013, 12:37:37 PM
Disappearing is likely Z-related. Keep in mind dynamic fonts are drawn using a separate draw call, so they have to be moved in front of your UI by adjusting Z (negative).

Corrupt font? Need repro steps for that.

\n in the text area -- why have it there? Just press Enter to create a new line.
Title: Re: Dynamic Fonts v2.6.0
Post by: jeldrez on April 24, 2013, 12:47:21 PM
Disappearing is likely Z-related. Keep in mind dynamic fonts are drawn using a separate draw call, so they have to be moved in front of your UI by adjusting Z (negative).
But it was working with the "old" dynamic font version, now it doesn't. How different they are?


Corrupt font? Need repro steps for that.
There's not to many steps, it happens all the time navigating between menu.

\n in the text area -- why have it there? Just press Enter to create a new line.
Because I test the localized text there, then just copy/paste to my .txt file. But I don't really need this, but the things above are important.
Title: Re: Dynamic Fonts v2.6.0
Post by: PoN on April 25, 2013, 04:44:48 AM
Aren when will you add dynamic fonts to the standart version NGUI ?
Title: Re: Dynamic Fonts v2.6.0
Post by: jarjin on April 25, 2013, 07:53:47 AM
I also want to know!~
Title: Re: Dynamic Fonts v2.6.0
Post by: glueng on April 25, 2013, 10:47:28 AM
Corrupt font? Need repro steps for that.
Observed that issue in our projects. It happens if dynamic font texture expands in Unity scene that have been already constructed(for example, some UILabel text changed from an Update() to string that contains new characters).

STR:

-create UI with 2 UILabel's that share one dynamic font. Make characters size large enough so font texture will expand if characters amount in the scene would increase.
-run the scene
-start typing different characters in the first label until font texture expands
result: the first label is ok, but the second one is corrupted
Title: Re: Dynamic Fonts v2.6.0
Post by: ArenMook on April 25, 2013, 12:45:15 PM
I'll release 2.6.0 when issues get ironed out.

@glueng: thanks, I'll investigate.
Title: Re: Dynamic Fonts v2.6.0
Post by: ArenMook on April 25, 2013, 01:39:42 PM
Right, then... not getting this issue. I created 2 dynamic fonts, 2 labels, entered some text into them, added a script to them that changes the text in Start() function to something that doesn't exist in the font yet, built to device -- works fine. Anything else you're doing differently?
Title: Re: Dynamic Fonts v2.6.0
Post by: jarjin on April 25, 2013, 08:57:48 PM
@ArenMook  If there is a font texture size limit (default is 256*256) on the NGUI2.6 dynamic font?????
Title: Re: Dynamic Fonts v2.6.0
Post by: glueng on April 26, 2013, 03:26:18 AM
...I created 2 dynamic fonts...

You need to use one dynamic font, the same for both labels.
Title: Re: Dynamic Fonts v2.6.0
Post by: PoN on April 26, 2013, 03:44:55 AM
I'll release 2.6.0 when issues get ironed out.
Thanks, i will be waiting for it.
Title: Re: Dynamic Fonts v2.6.0
Post by: glueng on April 26, 2013, 04:49:05 AM
added a script to them that changes the text in Start() function to something that doesn't exist in the font yet
And please note that expanding of font texture at Start doesn't corrupt labels. You need to add symbols from Update() to reproduce the issue.
Title: Re: Dynamic Fonts v2.6.0
Post by: ArenMook on April 26, 2013, 01:21:35 PM
Alright, duplicated a label using the same font. Modified the test script to this:
  1. using UnityEngine;
  2.  
  3. public class TestFnt : MonoBehaviour
  4. {
  5.         void Update ()
  6.         {
  7.                 if (Input.GetKeyDown(KeyCode.T))
  8.                 {
  9.                         UILabel lbl = GetComponent<UILabel>();
  10.                         lbl.text = "@$$^%*";
  11.                 }
  12.         }
  13. }
...again works fine.
Title: Re: Dynamic Fonts v2.6.0
Post by: glueng on April 29, 2013, 07:07:50 AM
...again works fine.

Did the font atlas expanded after characters adding? The issue happens ONLY if new characters doesn't fit current atlas size and force the font texture size to increase
Title: Re: Dynamic Fonts v2.6.0
Post by: jeldrez on April 29, 2013, 07:16:29 AM
Did the font atlas expanded after characters adding? The issue happens ONLY if new characters doesn't fit current atlas size and force the font texture size to increase
how do you have an atlas?
Title: Re: Dynamic Fonts v2.6.0
Post by: glueng on April 29, 2013, 07:43:40 AM
how do you have an atlas?

By atlas I mean dynamic font texture which contains characters.
Title: Re: Dynamic Fonts v2.6.0
Post by: jeldrez on April 29, 2013, 08:13:46 AM
By atlas I mean dynamic font texture which contains characters.
Ouhh, ok.
Title: Re: Dynamic Fonts v2.6.0
Post by: Nicki 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.
Title: Re: Dynamic Fonts v2.6.0
Post by: Ferazel 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 (http://docs.unity3d.com/Documentation/ScriptReference/Font-textureRebuildCallback.html) 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)
Title: Re: Dynamic Fonts v2.6.0
Post by: ArenMook 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. }
Title: Re: Dynamic Fonts v2.6.0
Post by: dlewis on April 29, 2013, 06:10:30 PM
If what ArenMook suggested doesn't work, create an example project/scene and post it.
Title: Re: Dynamic Fonts v2.6.0
Post by: ArenMook 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.
Title: Re: Dynamic Fonts v2.6.0
Post by: ArenMook 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.
Title: Re: Dynamic Fonts v2.6.0
Post by: jeldrez on May 02, 2013, 09:34:39 AM
Sorry, I'll try it tonight and let you know how it was.
Title: Re: Dynamic Fonts v2.6.0
Post by: jeldrez 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.  
Title: Re: Dynamic Fonts v2.6.0
Post by: dlewis 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.
Title: Re: Dynamic Fonts v2.6.0
Post by: maoguo.zhang 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? :)
Title: Re: Dynamic Fonts v2.6.0
Post by: ArenMook 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.
Title: Re: Dynamic Fonts v2.6.0
Post by: jeldrez on May 03, 2013, 01:06:11 PM
Thanks Aren.
I will try new version ASAP.
Title: Re: Dynamic Fonts v2.6.0
Post by: maoguo.zhang 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.
Title: Re: Dynamic Fonts v2.6.0
Post by: realblues 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?
Title: Re: Dynamic Fonts v2.6.0
Post by: ArenMook 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.
Title: Re: Dynamic Fonts v2.6.0
Post by: realblues on May 06, 2013, 02:12:06 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.

Well, I'm using Korean Font. It has English, Korean Glyph and Tested following:

1. Typing English in UILabel from Inspector (Editor, Play Mode) => OK

2. Typing English in UILabel inside UIInput from Inspector (Editor, PlayMode) =>OK

3. Typing English in UIInput (PlayMode) => OK

4. Typing Korean in UILabel from Inspector (Editor, Play Mode) => OK

5. Typing Korean in UILabel inside UIInput from Inspector(Editor, PlayMode) => OK
 
6.Typing Korean in UIInput ( PlayMode) => Fail

Fail Means, any Charactor added nothing. 

UILabel works fine every situation.  May be font looks not problem..
Title: Re: Dynamic Fonts v2.6.0
Post by: Kingtem on May 08, 2013, 06:49:01 AM
Well, I'm using Korean Font. It has English, Korean Glyph and Tested following:

1. Typing English in UILabel from Inspector (Editor, Play Mode) => OK

2. Typing English in UILabel inside UIInput from Inspector (Editor, PlayMode) =>OK

3. Typing English in UIInput (PlayMode) => OK

4. Typing Korean in UILabel from Inspector (Editor, Play Mode) => OK

5. Typing Korean in UILabel inside UIInput from Inspector(Editor, PlayMode) => OK
 
6.Typing Korean in UIInput ( PlayMode) => Fail

Fail Means, any Charactor added nothing. 

UILabel works fine every situation.  May be font looks not problem..

I've got the same problem. Can not input any unicode character from UIInput, but the UILabel seems work! And I test it with Unity "GUI", it can handle the case. For now, its very important for me. Aren, I need your help.  :o
Title: Re: Dynamic Fonts v2.6.0
Post by: ArenMook on May 08, 2013, 05:29:32 PM
Does Unity actually send the data in Input.inputString? If it doesn't, there is nothing I can do.
Title: Re: Dynamic Fonts v2.6.0
Post by: Kingtem on May 09, 2013, 07:47:19 AM
Does Unity actually send the data in Input.inputString? If it doesn't, there is nothing I can do.

Yeah, sure Unity could send data in it. And I found a strange thing: When I create a new project and inport NGUI 2.6.1d, then build an "exe" or Adroid app, both of them can input unicode, but for a previous project, even i replace the old NGUI, which still not work and just stop the application.
Title: Re: Dynamic Fonts v2.6.0
Post by: Arsmarin on June 27, 2013, 11:48:44 AM
I am using NGUI 2.6.3, but this problem still remains.
I've created 2 UILabel's, sharing the same Dynamic font. Before start, first label contains some text, so that Font texture is almost full.
In real-time, on button click, I sets the text of the second UILabel, so that the font texture is forced to rebuild.
First label is blinking on button click.
Title: Re: Dynamic Fonts v2.6.0
Post by: Nicki on June 27, 2013, 05:39:00 PM
Sounds like it's using an update cycle to complete it - or maybe to complete it and draw. Try sending the good old Refresh() or BroadcastMessage("CreatePanel") on the panel if the label that draws the label to see if that takes away the blink.
Title: Re: Dynamic Fonts v2.6.0
Post by: Arsmarin on June 28, 2013, 11:34:54 AM
I've added mPanel.Refresh() to UILabel.text setter and it works fine.
Title: Re: Dynamic Fonts v2.6.0
Post by: dkozlovtsev on August 15, 2013, 11:28:35 AM
This solution is not really good as it introduces uneeded mPanel.Refresh every time label text is changed, it is rather time consuming operation and in case of widget text changing every frame(for example timer in ms or something like this) causes considerable fps drop. Are there any better solutions for example is it possible to determine if texture actually got resized before calling mPanel.Refresh?