字体ttf文件裁剪&获取项目中所有字体文件插件

项目用到的字体过大,把字体适当裁剪,我们项目字体从9m顺利裁剪到2m

using System.Collections.Generic;
using System.IO;
using System.Text;
using UnityEditor;
using UnityEngine;

public class MyTool
{
    [MenuItem("Tools/GenFontTxt")]
    static void GenFontTxt()
    {
        StringBuilder sb = new StringBuilder();

        //遍历配置表文件夹下的配置文件
        string configpath = Application.dataPath + "/StreamingAssets/gamedata";
        string[] configpaths = Directory.GetFiles(configpath);
        var configlist = new List<string>();
        for (int i = 0; i < configpath.Length; i++)
        {
            string s = Path.GetExtension(configpaths[i]);
            if (s != ".meta")
            {
                configlist.Add(configpaths[i]);
            }
        }

        //保存目录
        string savepath = Application.dataPath + "/Font/FontTxt.txt";
        FileStream fs = File.Create(savepath);
        StreamWriter sw = new StreamWriter(fs);

        for (int i = 0; i < configlist.Count; i++)
        {
            Write(ref sw, configlist[i]);
        }

        //追加写入一些其他文档
        Write(ref sw, Application.dataPath + "/xxx1.txt");
        Write(ref sw, Application.dataPath + "/xxx2.txt");

        //追加常用3000字与符号
        Write(ref sw, Application.dataPath + "/Font/3000.txt");
        sw.Close();
        fs.Close();

        AssetDatabase.Refresh();
    }

    private static void Write(ref StreamWriter sw, string path)
    {
        FileStream fs1 = File.OpenRead(path);
        StreamReader sr1 = new StreamReader(fs1);
        sw.Write(sr1.ReadToEnd());
        fs1.Close();
        sr1.Close();
    }
}
利用SfntToolGUI.jar工具将字体裁剪。https://download.youkuaiyun.com/download/qq_31482599/10260762

                
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值