You've already forked taptap2024_GJ_chidouren
init
This commit is contained in:
56
Assets/Editor/FontTools.cs
Normal file
56
Assets/Editor/FontTools.cs
Normal file
@@ -0,0 +1,56 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user