[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中所有修订后的文字用特殊的字体(蓝色)标出来,然后再接受修订.我勒个去,明明有修订后的模式啊,为什 ...
随机推荐
- IDEA中使用springBoot+gradle构建多模块项目
https://blog.csdn.net/forMelo/article/details/78995875
- ionic platform add ios, Error:spawn EACCES
RT: cordova ionic 环境搭建好之后,需要添加平台才能打包,添加平台如果出错:Error:spawn EACCES, 原因是因为没添加hooks, 请使用 ionic add hooks ...
- 《LOST》 电视
还没看正剧,所以转来帮助看电视 从起源到终点:<LOST>剧情全解析(一) 此文是LOST完结之后的剧情解析,剧透,慎入 从起源到终点:<LOST>剧情全解析(一) 转 ...
- Vistual Studio XML 智能提示
开发中经常遇到要和各种各样的 XML 打交道,编辑 XML 文件时最头痛的便是要记住许多 XML 元素名称.属性名称. 幸运的是,Vistual Studio 的 XML 智能提示功能可以大大地减轻这 ...
- RTB业务知识之2-Impression概念和关键属性
一.定义-impression This object describes an ad placement or impression being auctioned. A single bid re ...
- ALGO-27_蓝桥杯_算法训练_FBI树(树,递归)
问题描述 我们可以把由“”和“”组成的字符串分为三类:全“”串称为B串,全“”串称为I串,既含“”又含“”的串则称为F串. FBI树是一种二叉树,它的结点类型也包括F结点,B结点和I结点三种.由一个长 ...
- mongoDB oplog的说明及应用
mongoDB oplog 说明 ts:8字节的时间戳,由4字节unix timestamp + 4字节自增计数表示.这个值很重要,在选举(如master宕机时)新primary时,会选择ts最大的那 ...
- QHBoxLayout移除控件
def clear_layout(widget, layout): buttons = widget.findChildren(QtGui.QPushButton) while layout.item ...
- 学习笔记之Python for Data Analysis
Python for Data Analysis, 2nd Edition https://www.safaribooksonline.com/library/view/python-for-data ...
- [UE4]Is Server判断是否在服务器端