[Unity工具]批量修改字体
效果图:


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工具]批量修改字体的更多相关文章
- [Unity工具]批量修改Texture
BatchModifyTexture.cs using UnityEngine; using System.Collections; using UnityEditor; using System.I ...
- Orcad CIS怎么批量修改字体大小
选中DSN,右键,design properties, schematic design,选择design properties.
- ansible非root用户批量修改root密码
前言: 由于线上服务器密码长久没有更新,现领导要求批量更换密码.线上的之前部署过salt,但由于各种因素没有正常使用. 使用自动化工具批量修改的计划搁浅了,后来领导给了个python多线程修改密码脚本 ...
- MathType中如何批量修改公式字体和大小
MathType中如何批量修改公式字体和大小 关于MathType : MathType 是由美国Design Science公司开发的功能强大的数学公式编辑器,它同时支持Windows和Macint ...
- unity工具IGamesTools之批量生成帧动画
unity工具IGamesTools批量生成帧动画,可批量的将指定文件夹下的帧动画图片自动生成对应的资源文件(Animation,AnimationController,Prefabs) unity工 ...
- 详解MathType中如何批量修改公式字体和大小
MathType应用在论文中时,有时会因为排版问题批量修改公式字体和大小,一个一个的修改不仅费时费力,还容易出现错误,本教程将详解如何在MathType公式编辑器中批量修改公式字体和大小. MathT ...
- C#代码生成工具:文本模板初体验 使用T4批量修改实体框架(Entity Framework)的类名
转自:http://www.cnblogs.com/huangcong/archive/2011/07/20/1931107.html 在之前的文本模板(T4)初体验中我们已经知道了T4的用处,下面就 ...
- unity批量修改AssetBundleName与Variant
批量修改指定路径下的资源的AssetBundleName与Variant. 脚本代码如下: using System.Collections; using System.Collections.Gen ...
- Word技巧杂记(二)——批量修改修订格式并接受
今天的题目好奇怪啊,呵呵,起因如下: 今天老婆在修改论文,她的老板提出一个非常**的要求——把Word中所有修订后的文字用特殊的字体(蓝色)标出来,然后再接受修订.我勒个去,明明有修订后的模式啊,为什 ...
随机推荐
- springMVC数据绑定入门
数据绑定是将用户输入绑定到领域模型的一种特性. @controller 注解使类生效 @RequestMapping(value="",meithod = RequestMetho ...
- Linux之用户组、文件权限详解
用户和用户组 文件所有者(u) 一般为文件的创建者,谁创建了该文件,就天然的成为该文件的所有者 用ls ‐ahl命令可以看到文件的所有者 也可以使用chown 用户名 文件名来修改文件的所有者 用户组 ...
- OpenTSDB(时序数据库官网)
官网地址:http://opentsdb.net/ 下载地址:https://github.com/OpenTSDB/opentsdb/releases ----------------------- ...
- WPF DataGrid添加编号列
WPF DataGrid添加编号列? 第一步:<DataGridTemplateColumn Header="编号" Width="50" MinWidt ...
- (转) SQL Server编程系列(1):SMO介绍
最近在项目中用到了有关SQL Server管理任务方面的编程实现,有了一些自己的心得体会,想在此跟大家分享一下,在工作中用到了SMO/SQL CLR/SSIS等方面的知识,在国内这方面的文章并不多见, ...
- 峰Redis学习(8)Redis 持久化AOF方式
第三节:Redis 的持久化之AOF 方式 AOF方式:将以日志,记录每一个操作 优势:安全性相对RDB方式高很多: 劣势:效率相对RDB方式低很多: 1)AOF方式需要配置: # Please ...
- consul-template + nginx部署高可用负载均衡
一.Consul-Template简介 Consul-Template是基于Consul的自动替换配置文件的应用.在Consul-Template没出现之前,大家构建服务发现系统大多采用的是Zooke ...
- 服务网关zuul之五:熔断
路由熔断 当我们的后端服务出现异常的时候,我们不希望将异常抛出给最外层,期望服务可以自动进行一降级.Zuul给我们提供了这样的支持.当某个服务出现异常时,直接返回我们预设的信息. 如果没有配置fall ...
- 不同AI学科之间的联系
这里只是引用deep learning中的关于不同AI学科之间联系的图示,如果想具体了解相关知识,深入学习深度学习,可以参考网站:http://www.deeplearningbook.org 下面是 ...
- Oracle 小技巧
Oracle小技巧 ###add at 18-10-11 1 ed 在sqlplus当中 如果前一条语句输入有误的话 可以输入ed再回车.在进行编辑 输入ed后有弹窗,可以对之前的输入语句进行编辑 ...