Author Topic: Dynamic Fonts in Flash  (Read 3276 times)

Pasty

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 8
    • View Profile
Dynamic Fonts in Flash
« on: September 11, 2014, 02:53:48 PM »
It seems that dynamic fonts are working in Flash player builds in Unity 4.5.3. Are there any plans to add support for this with NGUI?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Dynamic Fonts in Flash
« Reply #1 on: September 12, 2014, 04:05:04 AM »
It's just a simple matter of changing a few #ifs. I'll see about doing that for the next update.

Pasty

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 8
    • View Profile
Re: Dynamic Fonts in Flash
« Reply #2 on: September 15, 2014, 02:41:57 PM »
I looked into it myself and did the following:

removed #if !UNITY_FLASH wherever it preceded #define DYNAMIC_FONT (7 files)
UIFont.cs - replaced fontNames[] usage (No support in UnityEngine)
UILabel.cs - replaced use of '++usage' with sepeate line for incrementing
UILabel.cs - created custom LastIndexOfAny() and IndexOfAny() methods to replace incompatible ones
UIWidget.cs - switched to if (!(mOnRender == value)) since Flash doesn't support .Equals()

Seems OK now!

sluice

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 1
    • View Profile
Re: Dynamic Fonts in Flash
« Reply #3 on: September 16, 2014, 02:08:53 PM »
Also, had this issue. You both pointed me in the right direction but I still had to fiddle around...
Here's how to fix it, more precisly:  :D


1. In: NGUIText.cs, UILabel.cs & UIFont.cs
Change:
  1. #if !UNITY_3_5 && !UNITY_FLASH
  2. #define DYNAMIC_FONT
  3. #endif
to:
  1. #if !UNITY_3_5
  2. #define DYNAMIC_FONT
  3. #endif


2. In UILabel.cs
Change:
  1. mFontUsage[mActiveTTF] = ++usage;
to
  1. mFontUsage[mActiveTTF] = usage+1;


3. Lastly, in UIFont.cs
Change:
  1. #if DYNAMIC_FONT
  2.                 if (a.isDynamic && b.isDynamic && a.dynamicFont.fontNames[0] == b.dynamicFont.fontNames[0]) return true;
  3. #endif
to
  1. #if DYNAMIC_FONT && !UNITY_FLASH
  2.                 if (a.isDynamic && b.isDynamic && a.dynamicFont.fontNames[0] == b.dynamicFont.fontNames[0]) return true;
  3. #endif


4. VoilĂ ! You may need to re-import the NGUI folder (from the project view) by right-clicking and selecting re-import

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Dynamic Fonts in Flash
« Reply #4 on: September 17, 2014, 11:53:07 AM »
Thanks!