IncreaseTextFontSize.cs 846 B

123456789101112131415161718192021222324252627282930
  1. using UnityEngine;
  2. using UnityEditor;
  3. using UnityEngine.UI;
  4. public class IncreaseSelectedTextFontSize : MonoBehaviour
  5. {
  6. [MenuItem("Tools/Text字体工具/选中对象下字体大小+2")]
  7. private static void IncreaseFontSizeInSelected()
  8. {
  9. GameObject selected = Selection.activeGameObject;
  10. if (selected == null)
  11. {
  12. Debug.LogWarning("请先在场景中选择一个对象!");
  13. return;
  14. }
  15. Text[] texts = selected.GetComponentsInChildren<Text>(true); // true 包括未激活对象
  16. int count = 0;
  17. foreach (Text text in texts)
  18. {
  19. Undo.RecordObject(text, "Increase Font Size");
  20. text.fontSize += 2;
  21. EditorUtility.SetDirty(text);
  22. count++;
  23. }
  24. Debug.Log($"在 \"{selected.name}\" 下更新了 {count} 个 Text 字体大小 +2");
  25. }
  26. }