NGUI圖集字體

UIFont裏使用Symbols來指定字體時用Sprite前綴和名字自動分配的工具,前段時間工做須要時寫的,具體用法有空時再寫。ide

using UnityEngine;
using UnityEditor;
using System.Collections.Generic;

public class ParseFontAtlasWindow : EditorWindow
{
    [MenuItem ("CustomTools/ParseFontAtlasWindow")]
    static void Init ()
    {
        ParseFontAtlasWindow window = (ParseFontAtlasWindow)EditorWindow.GetWindow (typeof (ParseFontAtlasWindow));
        window.Show();
    }

    string atlasPrefix = string.Empty;

    void OnGUI ()
    {
        atlasPrefix = EditorGUILayout.TextField(atlasPrefix);
        if (GUILayout.Button("ParseAtlas"))
        {
            UIFont tempFont = GetSelectedFont();

            UIAtlas tempAtlas = tempFont.atlas;
            foreach(UISpriteData tempSpriteData in tempAtlas.spriteList)
            {
                if( tempSpriteData.name.StartsWith(atlasPrefix)) tempFont.AddSymbol(tempSpriteData.name.Remove(0,atlasPrefix.Length), tempSpriteData.name);
            }
            tempFont.MarkAsChanged();
        }

        if (GUILayout.Button("ClearSymbol"))
        {
            UIFont tempFont = GetSelectedFont();
            if(tempFont == null) return;
            tempFont.symbols.Clear();
            tempFont.MarkAsChanged();
        }

        if (GUILayout.Button("Active"))
        {
            UIFont tempFont = GetSelectedFont();
            if (tempFont == null) return;
            if (tempFont.bmFont.isValid) return;
            tempFont.bmFont.glyphs.Add(new BMGlyph());
            tempFont.MarkAsChanged();
        }
    }

    UIFont GetSelectedFont()
    {
        UIFont result = null;
        if(Selection.activeGameObject != null)
        {
            result = Selection.activeGameObject.GetComponent<UIFont> ();
        }
        return result;
    }
    
}
View Code
相關文章
相關標籤/搜索