效果图:

 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. Visual Studio 2010 出现关于ActivityLog.xml错误的解决方案

    在用VS编写程序是第一次会跳出“Visual Studio has encountered an exception.This may be caused by an extension. You c ...

  2. TransportClient 新建index,mappings dynamic_templates。

    public void createIndex(TransportClient client, String index){ CreateIndexRequest request = new Crea ...

  3. 使用keytool 生成数字keystore

    生成本地证书 在密钥库中生成本地数字证书:需要提供身份.加密算法.有效期等信息: keytool指令如下,产生的本地证书后缀名为:*.keystore keytool -genkeypair -key ...

  4. windows 下跟踪日志的几个工具总结

    1.baretailpro.exe 2.wintail.exe 3.vim(using tail bundle plugin) 4.Notepad++ (Plugin->Plugin Manag ...

  5. MFC程序显示控制台输出

    有的时候,我们用c写的一些东西,可能需要MFC作为UI输入参数进行测试,但是程序里有大量的printf操作,这就需要MFC程序启动的时候同时打开 一个控制台,用于标准输出 查询网络,大致方法有以下两种 ...

  6. vue之v-for

    vue.js 的循环渲染是依赖于 v-for 指令,它能够根据 vue 的实例里面的信息,循环遍历所需数据,然后渲染出相应的内容.它可以遍历数组类型以及对象类型的数据,js 里面的数组本身实质上也是对 ...

  7. 继续循环continue

    继续循环continue continue的作用是仅仅跳过本次循环,而整个循环体继续执行. 语句结构: for(初始条件;判断条件;循环后条件值更新) { if(特殊情况) { continue; } ...

  8. java基础阶段关于密码或账号字符数字的判断总结

    将字符串转成字符数组 首字母判断 思路:应该如何获取首字母 arr[0]为数组第一个元素即是首字母 数字判断true为数字false为非数字 "0123456789".contai ...

  9. Hibernate QBC

    QBC查询: Query By Criteria 使用面向对象的方式查询 和HQL单表查询相似,但不包含别名查询和具名查询   1 全表查询 Criteria ce = session.createC ...

  10. Junit4简单使用

    一.Junit4是JAVA语言的单元测试框架,用于编写和运行可重复的测试,可以大大提高效率 1.使用Junit4必须在项目中导入Junit4.har文件 2.新建Junit Test case 勾选s ...