using UnityEditor;
using UnityEngine;
using System.IO;
using System.Collections.Generic;
public class FontMaker : Editor
{
//本方法是通过裁切的sprite导出字体文件,裁切使用的是unity自带的sprite editor,方便操作。
//另外,裁切之后,每个sprite的名字的最后一个字符对应了ascii码的编码,比如:
//0: 我们只要将sprite的名字命名成xxx0,就可以了!
//由于使用到的了sprite加载,所以字体图片请放在Resources目录下面,等制作完毕,再把他们放到fonts文件夹或者其他文件夹中即可。
[MenuItem("Assets/CreateMyFontSprite")]
static void CreateMyFontSprite()
{
if (Selection.objects == null)
{
Debug.Log("Select = null");
return;
}
if (Selection.objects.Length == 0)
{
Debug.LogWarning("没有选中Sprite文件,需要将Sprite Mode设置成Multiple,切分好,并且以以名字的最后一个字符当做ascii码");
return;
}
string resoursePath = "Resources";
Object o = Selection.objects[0];
if (o.GetType() != typeof(Texture2D))
{
Debug.LogWarning("选中的并不是图片文件");
return;
}
string selectionPath = AssetDatabase.GetAssetPath(o);
if (selectionPath.Contains(resoursePath))
{
string selectionExt = Path.GetExtension(selectionPath);
if (selectionExt.Length == 0)
{
return;
}
string loadPath = selectionPath.Remove(selectionPath.Length - selectionExt.Length);
string fontPathName = loadPath + ".fontsettings";
string matPathName = loadPath + ".mat";
float lineSpace = 0.1f;//字体行间距,下面会根据最高的字体得到行间距,如果是固定高度,可以在这里自行调整
loadPath = Path.GetFileNameWithoutExtension(selectionPath)
unity 创建艺术字体工具
最新推荐文章于 2024-05-04 15:14:06 发布