Skip to content

Instantly share code, notes, and snippets.

@kimsama
Last active December 21, 2015 13:49
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kimsama/6315839 to your computer and use it in GitHub Desktop.
Save kimsama/6315839 to your computer and use it in GitHub Desktop.
A patch to fix NGUI 2.6.4. dynamic font problem which cause randomly disappearing of fonts.
diff -r 6e8e22fe6d82 Assets/NGUI/Scripts/Internal/UIWidget.cs
--- a/Assets/NGUI/Scripts/Internal/UIWidget.cs Thu Aug 08 12:15:03 2013 +0900
+++ b/Assets/NGUI/Scripts/Internal/UIWidget.cs Thu Aug 08 12:15:07 2013 +0900
@@ -7,6 +7,8 @@
#define OLD_UNITY
#endif
+#define DYNAMIC_FONT_BUG_FIX
+
using UnityEngine;
using System.Collections.Generic;
@@ -484,7 +486,11 @@
/// Clear references.
/// </summary>
+#if DYNAMIC_FONT_BUG_FIX
+ protected virtual void OnDisable ()
+#else
void OnDisable ()
+#endif
{
if (!keepMaterial)
{
diff -r 6e8e22fe6d82 Assets/NGUI/Scripts/UI/UIFont.cs
--- a/Assets/NGUI/Scripts/UI/UIFont.cs Thu Aug 08 12:15:03 2013 +0900
+++ b/Assets/NGUI/Scripts/UI/UIFont.cs Thu Aug 08 12:15:07 2013 +0900
@@ -10,6 +10,8 @@
#define DYNAMIC_FONT
#endif
+#define DYNAMIC_FONT_BUG_FIX
+
using UnityEngine;
using System.Collections.Generic;
using System.Text;
@@ -672,13 +674,21 @@
#endif
{
if (encoding) text = NGUITools.StripSymbols(text);
-#if DYNAMIC_FONT
+
+#if DYNAMIC_FONT_BUG_FIX
+ if (dynamic)
+ {
+ mDynamicFont.RequestCharactersInTexture(text, mDynamicFontSize, mDynamicFontStyle);
+ }
+#else
+# if DYNAMIC_FONT
if (dynamic)
{
mDynamicFont.textureRebuildCallback = OnFontChanged;
mDynamicFont.RequestCharactersInTexture(text, mDynamicFontSize, mDynamicFontStyle);
mDynamicFont.textureRebuildCallback = null;
}
+# endif
#endif
int length = text.Length;
int maxX = 0;
@@ -777,13 +787,20 @@
bool useSymbols = encoding && symbolStyle != SymbolStyle.None && hasSymbols;
bool dynamic = isDynamic;
-#if DYNAMIC_FONT
+#if DYNAMIC_FONT_BUG_FIX
+ if (dynamic)
+ {
+ mDynamicFont.RequestCharactersInTexture(text, mDynamicFontSize, mDynamicFontStyle);
+ }
+#else
+# if DYNAMIC_FONT
if (dynamic)
{
mDynamicFont.textureRebuildCallback = OnFontChanged;
mDynamicFont.RequestCharactersInTexture(text, mDynamicFontSize, mDynamicFontStyle);
mDynamicFont.textureRebuildCallback = null;
}
+# endif
#endif
while (currentCharacterIndex > 0 && remainingWidth > 0)
{
@@ -861,7 +878,15 @@
bool useSymbols = encoding && symbolStyle != SymbolStyle.None && hasSymbols;
bool dynamic = isDynamic;
-#if DYNAMIC_FONT
+#if DYNAMIC_FONT_BUG_FIX
+ // Make sure the characters are present in the dynamic font before printing them
+ if (dynamic)
+ {
+ mDynamicFont.RequestCharactersInTexture(text, mDynamicFontSize, mDynamicFontStyle);
+ }
+
+#else
+# if DYNAMIC_FONT
// Make sure the characters are present in the dynamic font before printing them
if (dynamic)
{
@@ -869,6 +894,7 @@
mDynamicFont.RequestCharactersInTexture(text, mDynamicFontSize, mDynamicFontStyle);
mDynamicFont.textureRebuildCallback = null;
}
+# endif
#endif
// Run through all characters
@@ -1098,13 +1124,21 @@
// Make sure the characters are present in the dynamic font before printing them
bool dynamic = isDynamic;
-#if DYNAMIC_FONT
+
+#if DYNAMIC_FONT_BUG_FIX
+ if (dynamic)
+ {
+ mDynamicFont.RequestCharactersInTexture(text, mDynamicFontSize, mDynamicFontStyle);
+ }
+#else
+# if DYNAMIC_FONT
if (dynamic)
{
mDynamicFont.textureRebuildCallback = OnFontChanged;
mDynamicFont.RequestCharactersInTexture(text, mDynamicFontSize, mDynamicFontStyle);
mDynamicFont.textureRebuildCallback = null;
}
+# endif
#endif
mColors.Clear();
mColors.Add(color);
diff -r 6e8e22fe6d82 Assets/NGUI/Scripts/UI/UILabel.cs
--- a/Assets/NGUI/Scripts/UI/UILabel.cs Thu Aug 08 12:15:03 2013 +0900
+++ b/Assets/NGUI/Scripts/UI/UILabel.cs Thu Aug 08 12:15:07 2013 +0900
@@ -2,9 +2,11 @@
// NGUI: Next-Gen UI kit
// Copyright © 2011-2013 Tasharen Entertainment
//----------------------------------------------
+#define DYNAMIC_FONT_BUG_FIX
using UnityEngine;
using System.Collections.Generic;
+using System.Collections;
using System;
[ExecuteInEditMode]
@@ -110,11 +112,26 @@
{
if (mFont != value)
{
+#if DYNAMIC_FONT_BUG_FIX
+ if (mFont != null && mFont.dynamicFont != null)
+ {
+ Debug.Log ("remove_old_font_texture_event_handler");
+ mFont.dynamicFont.textureRebuildCallback -= OnFontTextureUpdated;
+ }
+#endif
mFont = value;
material = (mFont != null) ? mFont.material : null;
mChanged = true;
hasChanged = true;
MarkAsChanged();
+
+#if DYNAMIC_FONT_BUG_FIX
+ if (mFont != null && mFont.dynamicFont != null)
+ {
+ Debug.Log ("add_new_font_texture_event_handler");
+ mFont.dynamicFont.textureRebuildCallback += OnFontTextureUpdated;
+ }
+#endif
}
}
}
@@ -674,4 +691,33 @@
}
}
}
+
+#if DYNAMIC_FONT_BUG_FIX
+ protected override void OnEnable ()
+ {
+ base.OnEnable ();
+
+ if (mFont != null && mFont.dynamicFont != null)
+ {
+ Debug.Log ("add_font_texture_event_handler");
+ mFont.dynamicFont.textureRebuildCallback += OnFontTextureUpdated;
+ }
+ }
+
+ protected override void OnDisable ()
+ {
+ if (mFont != null && mFont.dynamicFont != null)
+ {
+ Debug.Log ("remove_font_texture_event_handler");
+ mFont.dynamicFont.textureRebuildCallback -= OnFontTextureUpdated;
+ }
+ base.OnDisable ();
+ }
+
+ void OnFontTextureUpdated()
+ {
+ Debug.Log ("on_font_texture_updated:" + mText);
+ MarkAsChanged ();
+ }
+#endif
}
diff -r 6e8e22fe6d82 Assets/NGUI/Scripts/UI/UIPanel.cs
--- a/Assets/NGUI/Scripts/UI/UIPanel.cs Thu Aug 08 12:15:03 2013 +0900
+++ b/Assets/NGUI/Scripts/UI/UIPanel.cs Thu Aug 08 12:15:07 2013 +0900
@@ -11,6 +11,8 @@
#define OLD_UNITY
#endif
+#define DYNAMIC_FONT_BUG_FIX
+
using UnityEngine;
using System.Collections.Generic;
@@ -1040,7 +1042,11 @@
/// Main update function
/// </summary>
+#if DYNAMIC_FONT_BUG_FIX
+ void OnGUI ()
+#else
void LateUpdate ()
+#endif
{
mUpdateTime = Time.realtimeSinceStartup;
UpdateTransformMatrix();
@@ -1111,7 +1117,13 @@
{
UIWidget[] wd = GetComponentsInChildren<UIWidget>();
for (int i = 0, imax = wd.Length; i < imax; ++i) wd[i].Update();
+
+#if DYNAMIC_FONT_BUG_FIX
+ OnGUI();
+#else
LateUpdate();
+#endif
+
}
#if UNITY_EDITOR
@setimets
Copy link

setimets commented Sep 6, 2013

감사 합니다.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment