| 12345678910111213141516171819202122232425262728293031323334 | using UnityEngine;using UnityEditor;using UnityEngine.UI;public class ModifyTextFontStyle : MonoBehaviour{    [MenuItem("Tools/Text字体工具/选中对象下加粗字体变正常")]    private static void RemoveBoldFontStyleInSelected()    {        GameObject selected = Selection.activeGameObject;        if (selected == null)        {            Debug.LogWarning("请先在场景中选择一个对象!");            return;        }        Text[] texts = selected.GetComponentsInChildren<Text>(true); // true 包括未激活对象        int count = 0;        foreach (Text text in texts)        {            // 如果字体是加粗的,就设置为正常            if (text.fontStyle == FontStyle.Bold)            {                Undo.RecordObject(text, "Remove Bold Font Style");                text.fontStyle = FontStyle.Normal;                EditorUtility.SetDirty(text);                count++;            }        }        Debug.Log($"在 \"{selected.name}\" 下更新了 {count} 个加粗字体为正常");    }}
 |