Hi,
I ran into this issue a month ago and since then I've been patching every release of NGUI. I thought it might be better to share this and see what others think.
You won't see this issue if your font is part of an existing sprite atlas. The problem exists when you try to create different font atlases to support retina using the font reference feature.
The main issue appears in UILabel.cs / line 478 & 513:
float pixelSize = (font.atlas != null) ? font.atlas.pixelSize : 1f;
The result is that font atlases always end up with a pixel size of 1.0 (which is bad).
My current fix is as follows (tested on v2.2.6 c):
in UIFont.cs / line 39 insert:
// Size in pixels for the sake of MakePixelPerfect functions.
[HideInInspector][SerializeField] float mPixelSize = 1f;
in UIFont.cs / line 72 insert:
/// <summary>
/// Pixel size is a multiplier applied to widgets dimensions when performing MakePixelPerfect() pixel correction.
/// Most obvious use would be on retina screen displays. The resolution doubles, but with UIRoot staying the same
/// for layout purposes, you can still get extra sharpness by switching to an HD atlas that has pixel size set to 0.5.
/// </summary>
public float pixelSize
{
get
{
return (mReplacement != null) ? mReplacement.pixelSize : mPixelSize;
}
set
{
if (mReplacement != null)
{
mReplacement.pixelSize = value;
}
else
{
float val = Mathf.Clamp(value, 0.25f, 4f);
if (mPixelSize != val)
{
mPixelSize = val;
MarkAsDirty();
}
}
}
}
in UILabel.cs / line 478 replace with:
float pixelSize = (font.atlas != null) ? font.atlas.pixelSize : font.pixelSize;
in UILabel.cs / line 513 replace with:
float pixelSize = (font.atlas != null) ? font.atlas.pixelSize : font.pixelSize;
in UIFontInspector / line 243 insert:
float pixelSize = EditorGUILayout.FloatField("Pixel Size", mFont.pixelSize, GUILayout.Width(120f));
if (pixelSize != mFont.pixelSize)
{
NGUIEditorTools.RegisterUndo("Font Change", mFont);
mFont.pixelSize = pixelSize;
}
Is there a better solution to this problem?
Thanks.