三国卡牌客户端基础资源仓库
hch
2025-06-04 70909cbb5996d817fd417f634f47418188e46d0f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
using UnityEngine;
using System.Collections;
using UnityEditor;
using System.Text;
 
public class FontMaker
{
    static public Font m_myFont;
    static public TextAsset m_data;
    static private BMFont mbFont = new BMFont();
 
    static public void GenerateCharacterInfo()
    {
 
        CustomFontReader.Load(mbFont, m_data.name, m_data.bytes);
        CharacterInfo[] characterInfo = new CharacterInfo[mbFont.glyphs.Count];
        for (int i = 0; i < mbFont.glyphs.Count; i++)
        {
            BMGlyph bmInfo = mbFont.glyphs[i];
            CharacterInfo info = new CharacterInfo();
            info.index = bmInfo.index;
            info.uv.x = (float)bmInfo.x / (float)mbFont.texWidth;
            info.uv.y = 1 - (float)bmInfo.y / (float)mbFont.texHeight;
            info.uv.width = (float)bmInfo.width / (float)mbFont.texWidth;
            info.uv.height = -1f * (float)bmInfo.height / (float)mbFont.texHeight;
            info.vert.x = (float)bmInfo.offsetX;
            info.vert.y = (float)bmInfo.offsetY;
            info.vert.width = (float)bmInfo.width;
            info.vert.height = (float)bmInfo.height;
            info.width = (float)bmInfo.advance;
            characterInfo[i] = info;
        }
        m_myFont.characterInfo = characterInfo;
 
        EditorUtility.SetDirty(m_myFont);
        AssetDatabase.SaveAssets();
        AssetDatabase.Refresh();
    }
 
    [MenuItem("策划工具/美术字制作")]
    static public void OpenFontMakerWindow()
    {
        Rect windowRect = new Rect(Screen.width / 2 - 200, Screen.height / 2 - 100, 400, 200);
        FontMakerWindow modalTipswindow = EditorWindow.GetWindowWithRect<FontMakerWindow>(windowRect, true, "自定义字体编辑器", false);
    }
 
}