Author Topic: How to use UIFont(Dynamic) in NGUI3.0.7  (Read 4139 times)

leo414

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 4
    • View Profile
How to use UIFont(Dynamic) in NGUI3.0.7
« on: September 23, 2014, 12:31:09 PM »
I ask the question in this topic:
http://www.tasharen.com/forum/index.php?topic=4241.msg52342#msg52342
but no one help.So I post a new topic waiting for help:

I select "DynamicFont_WithSymblo".But it's still none(look at the attachment).
Then I changed OnBitmapFont and test it:
void OnBitmapFont (Object obj)
{
   serializedObject.Update();
   SerializedProperty sp = serializedObject.FindProperty("mFont");
   sp.objectReferenceValue = obj;
   serializedObject.ApplyModifiedProperties();
   NGUISettings.ambigiousFont = obj;
   Debug.Log("objectReferenceInstanceIDValue:" + serializedObject.FindProperty("mFont").objectReferenceInstanceIDValue);
   serializedObject.Update();
   Debug.Log("objectReferenceInstanceIDValue:" + serializedObject.FindProperty("mFont").objectReferenceInstanceIDValue);
   if(serializedObject.FindProperty("mFont").objectReferenceValue == null)
      Debug.Log("objectReferenceValue is null");
}

The result is:
objectReferenceInstanceIDValue:9992.
objectReferenceInstanceIDValue:0.
objectReferenceValue is null

How to use UIFont(Dynamic) in NGUI3.0.7?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: How to use UIFont(Dynamic) in NGUI3.0.7
« Reply #1 on: September 23, 2014, 12:44:40 PM »
NGUI 3.0.7 is like a year out of date. Why are you using such an old version? I can't support something that old. To use dynamic fonts with the current version, you don't need to create a UIFont at all. Just create a label, choose "Unity" type font, and then choose the TTF.

That said, I don't advise using dynamic fonts. They are bugged on Unity's side, and there is nothing I can do about it.

leo414

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 4
    • View Profile
Re: How to use UIFont(Dynamic) in NGUI3.0.7
« Reply #2 on: September 23, 2014, 10:44:25 PM »
I use NGUI 3.0.7 and Unity 4.1.5 in an old project.So it's a risk to upgrade Unity and NGUI.
It's OK if the UIFont's type is normal.
But objectReferenceValue is null when the UIFont's type is dynamic.
Could you tell me why?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: How to use UIFont(Dynamic) in NGUI3.0.7
« Reply #3 on: September 24, 2014, 01:43:45 PM »
Because "mFont" is a bitmap font. You want "mTrueTypeFont", at least in the up to date version of NGUI.

leo414

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 4
    • View Profile
Re: How to use UIFont(Dynamic) in NGUI3.0.7
« Reply #4 on: September 24, 2014, 09:36:38 PM »
I changed OnBitmapFont and test.I think the problem is that it can not be serialized or deserialized:

void OnBitmapFont (Object obj)
{
   serializedObject.Update();
   SerializedProperty sp = serializedObject.FindProperty("mFont");
   sp.objectReferenceValue = obj;
   serializedObject.ApplyModifiedProperties();
   NGUISettings.ambigiousFont = obj;
   Debug.Log("objectReferenceInstanceIDValue:" + serializedObject.FindProperty("mFont").objectReferenceValue);
   serializedObject.Update();
   Debug.Log("objectReferenceInstanceIDValue:" + serializedObject.FindProperty("mFont").objectReferenceValue);
   if(serializedObject.FindProperty("mFont").objectReferenceValue == null)
      Debug.Log("objectReferenceValue is null");
}

The result is:
objectReferenceInstanceIDValue:DynamicFont_WithSymblo (UIFont)            //it's right
objectReferenceInstanceIDValue:                                                           //It's wrong after   "serializedObject.Update()"
objectReferenceValue is null
« Last Edit: September 24, 2014, 09:47:54 PM by leo414 »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: How to use UIFont(Dynamic) in NGUI3.0.7
« Reply #5 on: September 25, 2014, 07:04:32 PM »
What... are you doing...
  1. // this updates the serialized object, letting you work with it.
  2. serializedObject.Update();
  3.  
  4. // You get the 'mFont', which is a BITMAP font. Why are you still getting a BITMAP font if you want to set a DYNAMIC font?
  5. SerializedProperty sp = serializedObject.FindProperty("mFont");
  6. sp.objectReferenceValue = obj;
What you should be doing instead is:
  1. SerializedProperty sp = serializedObject.FindProperty("mTrueTypeFont");
  2. sp.objectReferenceValue = obj;
I'm helping you do something in a custom third-party script using a version of NGUI that's a year out of date... This is as much as I can do here.