效果图:

 using System.IO;
using System.Text;
using UnityEditor;
using UnityEngine;
using UnityEngine.UI; /// <summary>
/// 将目标文件夹下所有Prefab的丢失、默认字体的位置输出,并替换成目标字体
/// </summary>
public class BatchModifyFontWindow : EditorWindow { Font toFont = new Font("Arial");//目标字体
string searchFolder = "Assets/Resources/Prefabs";//目标文件夹
string outputPath = Application.dataPath + "/BatchModifyFont.txt";//输出文件路径
bool needReplace = false;//是否要进行替换 [MenuItem("Window/Custom/BatchModifyFontWindow")]
private static void ShowWindow()
{
EditorWindow.GetWindow<BatchModifyFontWindow>(true, "批量修改字体", true);
} void OnGUI()
{
EditorGUILayout.LabelField("功能描述:将目标文件夹下所有Prefab的丢失、默认字体的位置输出,并替换成目标字体"); GUILayout.BeginHorizontal();
EditorGUILayout.LabelField("目标文件夹为:" + searchFolder);
if (GUILayout.Button("选择文件夹"))
{
string temp = EditorUtility.OpenFolderPanel("请选择目标文件夹", Application.dataPath, "");
if (!string.IsNullOrEmpty(temp))
{
temp = temp.Substring(temp.IndexOf("Assets"));
searchFolder = temp;
}
}
GUILayout.EndHorizontal(); EditorGUILayout.LabelField("输出文件路径:" + outputPath); GUILayout.BeginHorizontal();
GUILayout.Label("目标字体为:");
toFont = (Font)EditorGUILayout.ObjectField(toFont, typeof(Font), true, GUILayout.MinWidth(100f));
GUILayout.EndHorizontal(); GUILayout.BeginHorizontal();
string replaceBtnStr;
if (needReplace)
{
replaceBtnStr = "输出要替换的位置并替换字体";
}
else
{
replaceBtnStr = "输出要替换的位置";
}
if (GUILayout.Button(replaceBtnStr))
{
StringBuilder builder = new StringBuilder();
int counter = ;
string[] guids = AssetDatabase.FindAssets("t:Prefab", new string[] { searchFolder });
for (int i = ; i < guids.Length; i++)
{
string path = AssetDatabase.GUIDToAssetPath(guids[i]);
//Debug.Log(path);
EditorUtility.DisplayProgressBar("Hold on", path, (float)(i + ) / guids.Length); bool hasModifyFont = false;
GameObject go = AssetDatabase.LoadAssetAtPath<GameObject>(path);
Text[] texts = go.GetComponentsInChildren<Text>(true);
for (int j = ; j < texts.Length; j++)
{
Text text = texts[j];
string fontName;
string log;
if (text.font)
{
fontName = text.font.name;
}
else
{
fontName = "Missing";
} log = path.Substring(, path.LastIndexOf("/")) + "/" + GetFontPath(go.transform, text.transform) + fontName;
//Debug.Log(log); //对丢失、默认字体进行处理
if ((fontName == "Missing") || (fontName == "Arial"))
{
if (needReplace)
{
text.font = toFont;
hasModifyFont = true;
}
counter++;
builder.Append(log + "\r\n");
Debug.Log(log);
}
} if (hasModifyFont)
{
EditorUtility.SetDirty(go);
}
} if (needReplace)
{
Debug.Log(string.Format("替换完成。替换了{0}处", counter));
}
else
{
Debug.Log(string.Format("需要替换{0}处", counter));
}
File.WriteAllText(outputPath, builder.ToString());
AssetDatabase.Refresh();
EditorUtility.ClearProgressBar();
}
EditorGUILayout.LabelField("替换字体");
needReplace = EditorGUILayout.Toggle(needReplace);
GUILayout.EndHorizontal();
} string GetFontPath(Transform parentTra, Transform fontTra)
{
string path = "";
while (parentTra != fontTra)
{
path = fontTra.gameObject.name + "/" + path;
fontTra = fontTra.parent;
}
return parentTra.gameObject.name + "/" + path;
}
}

[Unity工具]批量修改字体的更多相关文章

  1. [Unity工具]批量修改Texture

    BatchModifyTexture.cs using UnityEngine; using System.Collections; using UnityEditor; using System.I ...

  2. Orcad CIS怎么批量修改字体大小

    选中DSN,右键,design properties, schematic design,选择design properties.

  3. ansible非root用户批量修改root密码

    前言: 由于线上服务器密码长久没有更新,现领导要求批量更换密码.线上的之前部署过salt,但由于各种因素没有正常使用. 使用自动化工具批量修改的计划搁浅了,后来领导给了个python多线程修改密码脚本 ...

  4. MathType中如何批量修改公式字体和大小

    MathType中如何批量修改公式字体和大小 关于MathType : MathType 是由美国Design Science公司开发的功能强大的数学公式编辑器,它同时支持Windows和Macint ...

  5. unity工具IGamesTools之批量生成帧动画

    unity工具IGamesTools批量生成帧动画,可批量的将指定文件夹下的帧动画图片自动生成对应的资源文件(Animation,AnimationController,Prefabs) unity工 ...

  6. 详解MathType中如何批量修改公式字体和大小

    MathType应用在论文中时,有时会因为排版问题批量修改公式字体和大小,一个一个的修改不仅费时费力,还容易出现错误,本教程将详解如何在MathType公式编辑器中批量修改公式字体和大小. MathT ...

  7. C#代码生成工具:文本模板初体验 使用T4批量修改实体框架(Entity Framework)的类名

    转自:http://www.cnblogs.com/huangcong/archive/2011/07/20/1931107.html 在之前的文本模板(T4)初体验中我们已经知道了T4的用处,下面就 ...

  8. unity批量修改AssetBundleName与Variant

    批量修改指定路径下的资源的AssetBundleName与Variant. 脚本代码如下: using System.Collections; using System.Collections.Gen ...

  9. Word技巧杂记(二)——批量修改修订格式并接受

    今天的题目好奇怪啊,呵呵,起因如下: 今天老婆在修改论文,她的老板提出一个非常**的要求——把Word中所有修订后的文字用特殊的字体(蓝色)标出来,然后再接受修订.我勒个去,明明有修订后的模式啊,为什 ...

随机推荐

  1. 【转】利用Psyco提升Python运行速度

    转自:http://www.leeon.me/a/use-Psyco-to-improve-Python-speed Psyco 是严格地在 Python 运行时进行操作的.也就是说,Python 源 ...

  2. SqlServer :利用快捷键快速查看 字段说明查询及表结构 (小技巧)

    1.自定义4个常用的存储过程: sp_select :select * from sp_helpremark :查表的列,列的类型,备注(这里只查询有备注的列) sp_columns1 : 查表所有的 ...

  3. Linux命令之shutdown

    shutdown命令安全地将系统关机. 有些用户会使用直接断掉电源的方式来关闭linux,这是十分危险的.因为linux与windows不同,其后台运行着许多进程,所以强制关机可能会导致进程的数据丢失 ...

  4. OpenWrt挂载移动硬盘实现脱机下载

    一.编译选项选好好usb存储驱动,参考http://www.cnblogs.com/smbx-ztbz/p/4418245.html 并且选上kmod-usb-hid,用于usbhub. 二.编译选项 ...

  5. Arduino在64位WIN7下无法安装驱动的解决办法

    1.获取权限 打开C:\Windows\System32\DriverStore\FileRepository,对着FileRepository文件夹,右键 >>属性 >>安全 ...

  6. java面试题002

    1.判断下列代码的运行情况 public class TestExtends { public static void main(String[] args) { Father obj = new S ...

  7. flume 架构设计优化

    对于企业中常用的flume type 概括如下:ource(获取数据源): exec (文件) spoolingdir (文件夹) taildir(文件夹及文件的变动) kafka syslog ht ...

  8. Avalon总线学习 ---Avalon Interface Specifications

    Avalon总线学习 ---Avalon Interface Specifications 1.Avalon Interfaces in a System and Nios II Processor ...

  9. Windows 消息【二】窗口函数

    前一篇文章讲到非队列消息会直接把消息Dispatch到窗口函数上,窗口函数长什么样? //就是一个大case分支 //要想拦截消息,override窗口函数是一个办法! procedure TCust ...

  10. C# .NET 4.5 将多个文件添加到压缩包中

    string zipFilePath = @"d:\test.zip"; string file1 = @"D:\门头照处理\门店照片2018-3-19 wuxl\门店照 ...