Files
taptap2024_GJ_chidouren/Assets/Editor/FontTools.cs
2024-10-16 00:03:41 +08:00

56 lines
1.7 KiB
C#

using TMPro;
using UnityEditor;
using UnityEngine;
namespace BuildEditor
{
public class FontTools
{
[MenuItem("Build/替换所有Text字体 (空检查替换)")]
public static void ReplaceTTF_safe()
{
ReplaceFont();
}
[MenuItem("Build/替换所有Text字体 (全部替换)")]
public static void ReplaceTTF()
{
ReplaceFont(false);
}
private static void ReplaceFont(bool safe = true)
{
var activeGameObject = Selection.activeGameObject;
if (activeGameObject != null)
{
var texts = activeGameObject.GetComponentsInChildren<TextMeshProUGUI>(true);
if (texts == null || texts.Length == 0)
{
return;
}
// var font = AssetDatabase.LoadAssetAtPath<TMP_FontAsset>("Assets/Sources/CustomFonts/siyuanheiti.ttf");
// var defaultSettings = TMP_Settings.LoadDefaultSettings();
// defaultSettings.
// Textme
foreach (var te in texts)
{
if (safe)
{
if (te.font == null)
{
te.font = TMP_Settings.defaultFontAsset;
}
}
else
{
te.font = TMP_Settings.defaultFontAsset;
}
}
// PrefabUtility.ApplyPrefabInstance(activeGameObject, InteractionMode.AutomatedAction);
}
}
}
}