unity 创建艺术字体工具

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)
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值