本工具就如标题一样,是用来批量替换unity中Text组件中的字体的工具。
原理就是查找文件夹下的所有预制体,批量修改预制体中存在的Text组件的字体数据。有做一个指定某种字体替换到另外一种字体的功能,这里我还拓展了字体风格的修改。
工具面板如下:
话不多说,代码如下:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using UnityEngine.UI;
using System.IO;
using System.Linq;
using System;
using Unity.Linq;
/// <summary>
/// Text字体修改工具
/// </summary>
public class FontChangeTool : EditorWindow
{
private string path;
List<GameObject> prefabList = new List<GameObject>();
string[] assetsPaths = new string[0];
List<bool> flagList ;
Vector2 scallPos;
static FontChangeTool window;
bool isSpecifyFontReplace;//是否指定字体更换
Font oldFont;
Font toChange;
static Font toChangeFont;
bool isFontStyleReplace;//是否需要替换字体风格
FontStyle toFontStyle;
static FontStyle toChangeFontStyle;
private void OnGUI()
{
RefreshUI();
}
[MenuItem("Tools/FontChangeTool/字体设置")]
public static void InitFont()
{
window = (FontChangeTool)GetWindow(typeof(FontChangeTool));
window.titleContent.text = "字体设置";
window.position = new Rect(PlayerSettings.defaultScreenWidth /