QQ聊天

NGUI图集字体

UIFont里使用Symbols来指定字体时用Sprite前缀和名字自动分配的工具,前段时间工作需要时写的,具体用法有空时再写。

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

 

posted @ 2015-10-21 17:07  SITT  阅读(528)  评论(0编辑  收藏  举报
QQ聊天