项目用到的字体过大,把字体适当裁剪,我们项目字体从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