代码比较简单,主要是项目频繁的遇到数字字体,为了方便写了个小工具,直接导入项目就可以使用。
要求美工必须把字体均匀大小的整齐排序好。
例如:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
using UnityEditor;
public class CustomFontCreator : EditorWindow
{
float m_TileWidth;
float m_TileHeight;
float m_TileMaxY;
string m_Key = "0123456789";
bool m_UseFontTxt;
[MenuItem("Tools/CustomFontCreator")]
static void Init()
{
var window = (CustomFontCreator)EditorWindow.GetWindow(typeof(CustomFontCreator));
window.Show();
}
void OnGUI()
{
var tex = Selection.activeObject as Texture;
if (tex == null)
{
EditorGUILayout.LabelField("请选择一张字体贴图");
}
else
{
var texWidth = tex.width;
var texHeith = tex.height;
EditorGUILayout.BeginVertical();
if (!m_UseFontTxt)
{
m_Key = EditorGUILayout.TextField("Keys", m_Key);
if (m_TileWidth == 0 && m_Key.Length > 0)
{
m_TileWidth = texWidth / m_Key.Length;
}
if (m_TileHeight == 0)
{
m_TileHeight = texHeith;
}