效果图:

 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. MSSQL 2012 密钥

    MICROSOFT SQL SERVER 2012 企业核心版激活码序列号: FH666-Y346V-7XFQ3-V69JM-RHW28 MICROSOFT SQL SERVER 2012 商业智能版 ...

  2. nginx 隐藏 index.php

    使用情景如下: 在访问 http://php.cc/Att/AttList 的时候.跳转到 http://php.cc/index.php/Att/AttList : 也就是开启重写功能: 在ngin ...

  3. DS哈希查找--线性探测再散列

    题目描述 定义哈希函数为H(key) = key%11.输入表长(大于.等于11),输入关键字集合,用线性探测再散列构建哈希表,并查找给定关键字. --程序要求-- 若使用C++只能include一个 ...

  4. ALGO-146_蓝桥杯_算法训练_4-2找公倍数

    AC代码: #include <stdio.h> int main(void) { int i; ; i <= ; i ++) { == && i% == ) { p ...

  5. 统计apk或jar中方法数量

    一.apk中方法数量 ./android-sdk-linux/build-tools/23.0.2/dexdump -f  apk路径 | grep method_ids_size 二.jar中方法数 ...

  6. Qt布局管理: 停靠窗口QDockWidget类(纯代码实现)

    转载:好儿郎~志在四方 详细描述: QDockWidget类提供了一个窗体部件,其可以停靠在QMainWindow,或其本身作为一个在桌面上的顶级窗口(也就是父窗体). QDockWidget类提供了 ...

  7. Android开发之Activity生命周期篇

    一.Activity: 1.Activity:Activity是一个与用记交互的系统模块,几乎所有的Activity都是和用户进行交互的. 2.在Android中Activity主要是用来做控制的,它 ...

  8. python 指定文件编码的方法

    import sys reload(sys) sys.setdefaultencoding('utf-8')

  9. [转][Oracle]常见报错及处理

    IIS 在安装 Oracle Client 后,需要命令行执行: iisreset 1.ORA-00257 参考自:https://jingyan.baidu.com/article/f71d6037 ...

  10. jquery插件:select、checkbox、radio的美化

    引用文件:  <script src=”/InputPick/jqInputFormat.js” type=”text/javascript”></script> <li ...