152 lines
4.8 KiB
C#
152 lines
4.8 KiB
C#
//----------------------------------------------
|
|
// NGUI: Next-Gen UI kit
|
|
// Copyright © 2011-2014 Tasharen Entertainment
|
|
//----------------------------------------------
|
|
|
|
#if !UNITY_3_5 && !UNITY_FLASH
|
|
#define DYNAMIC_FONT
|
|
#endif
|
|
|
|
using UnityEngine;
|
|
using UnityEditor;
|
|
using System.Collections.Generic;
|
|
using Thousandto.DIY;
|
|
using System.IO;
|
|
|
|
/// <summary>
|
|
/// Inspector class used to edit UILabels.
|
|
/// </summary>
|
|
[CustomEditor(typeof(UILabel), true)]
|
|
public partial class UILabelInspectorEx : CustomUILabelEditor
|
|
{
|
|
#region//私有变量
|
|
//字体选择
|
|
private int mSelectValue = 0;
|
|
#endregion
|
|
|
|
protected override bool ShouldDrawProperties()
|
|
{
|
|
DrawCustomStyle(target as UILabel);
|
|
return base.ShouldDrawProperties();
|
|
}
|
|
|
|
|
|
#region //定义由NGUI的原始UILabelInsprector调用的方法
|
|
//画自定义的样式
|
|
private void DrawCustomStyle(UILabel lable)
|
|
{
|
|
var prefabType = PrefabUtility.GetPrefabType(Selection.activeGameObject);
|
|
if (prefabType <= PrefabType.ModelPrefab) return;
|
|
serializedObject.Update();
|
|
GUILayout.Space(10);
|
|
if (GUILayout.Button("InitAllFontName"))
|
|
{
|
|
InitAllFontName();
|
|
}
|
|
GUILayout.BeginHorizontal();
|
|
{
|
|
|
|
if (_fontNames != null && _fontNames.Length > 0)
|
|
{
|
|
EditorGUILayout.LabelField("Custom Style");
|
|
var tmp = EditorGUILayout.Popup(mSelectValue, _fontNames);
|
|
if (mSelectValue != tmp)
|
|
{
|
|
mSelectValue = tmp;
|
|
UILabel skin = AssetDatabase.LoadAssetAtPath(_fontPaths[mSelectValue], typeof(UILabel)) as UILabel;
|
|
SetFontSkin(lable, skin);
|
|
serializedObject.ApplyModifiedProperties();
|
|
}
|
|
}
|
|
}
|
|
GUILayout.EndHorizontal();
|
|
GUILayout.Space(12);
|
|
}
|
|
#endregion
|
|
|
|
#region //私有方法
|
|
|
|
//字体名字列表
|
|
private static string[] _fontNames = null;
|
|
//字体路径
|
|
private static string[] _fontPaths = null;
|
|
//获取所有字体的名字
|
|
private void InitAllFontName()
|
|
{
|
|
if (_fontPaths == null)
|
|
{
|
|
_fontPaths = Directory.GetFiles("Assets/GameAssets/RawResources/ui/Skin/", "*.prefab");
|
|
_fontNames = new string[_fontPaths.Length];
|
|
for (int i = 0; i < _fontPaths.Length; i++)
|
|
{
|
|
_fontNames[i] = System.IO.Path.GetFileNameWithoutExtension(_fontPaths[i]);
|
|
}
|
|
}
|
|
}
|
|
//设置字体样式
|
|
private void SetFontSkin(UILabel src, UILabel skin)
|
|
{
|
|
if (src == null) return;
|
|
|
|
if (skin == null)
|
|
{
|
|
SetNormalFont(src);
|
|
src.color = Color.white;
|
|
src.effectStyle = UILabel.Effect.Shadow;
|
|
src.effectColor = Color.gray;
|
|
src.gradientTop = Color.white;
|
|
src.gradientBottom = Color.white;
|
|
return;
|
|
}
|
|
|
|
if (src && skin)
|
|
{
|
|
if (skin.bitmapFont != null)
|
|
{
|
|
src.bitmapFont = skin.bitmapFont;
|
|
}
|
|
else
|
|
{
|
|
src.trueTypeFont = skin.trueTypeFont;
|
|
}
|
|
src.color = skin.color;
|
|
src.fontSize = skin.fontSize;
|
|
src.fontStyle = skin.fontStyle;
|
|
//src.overflowMethod = skin.overflowMethod;
|
|
src.spacingX = skin.spacingX;
|
|
src.spacingY = skin.spacingY;
|
|
src.supportEncoding = skin.supportEncoding;
|
|
src.applyGradient = skin.applyGradient;
|
|
src.gradientTop = skin.gradientTop;
|
|
src.gradientBottom = skin.gradientBottom;
|
|
src.effectStyle = skin.effectStyle;
|
|
src.effectColor = skin.effectColor;
|
|
src.effectDistance = skin.effectDistance;
|
|
src.keepCrispWhenShrunk = skin.keepCrispWhenShrunk;
|
|
}
|
|
mFontType = (src.bitmapFont == null) ? FontType.Unity : FontType.NGUI ;
|
|
}
|
|
//设置正常字体
|
|
private void SetNormalFont(UILabel lab, FontStyle fs = FontStyle.Normal)
|
|
{
|
|
if (lab)
|
|
{
|
|
var font = AssetDatabase.LoadAssetAtPath("Assets/GameAssets/Resources/GameUI/Base/Font/BaseFont.prefab", typeof(UIFont)) as UIFont;
|
|
lab.fontSize = font.defaultSize;
|
|
if (font.isDynamic)
|
|
{
|
|
lab.keepCrispWhenShrunk = UILabel.Crispness.Never;
|
|
lab.trueTypeFont = font.dynamicFont;
|
|
lab.fontStyle = fs;
|
|
}
|
|
else
|
|
{
|
|
lab.keepCrispWhenShrunk = UILabel.Crispness.OnDesktop;
|
|
lab.bitmapFont = font;
|
|
lab.fontStyle = fs;
|
|
}
|
|
}
|
|
}
|
|
#endregion
|
|
}
|