123456789101112131415161718192021222324252627282930 |
- using UnityEngine;
- using UnityEditor;
- using UnityEngine.UI;
- public class IncreaseSelectedTextFontSize : MonoBehaviour
- {
- [MenuItem("Tools/Text字体工具/选中对象下字体大小+2")]
- private static void IncreaseFontSizeInSelected()
- {
- 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)
- {
- Undo.RecordObject(text, "Increase Font Size");
- text.fontSize += 2;
- EditorUtility.SetDirty(text);
- count++;
- }
- Debug.Log($"在 \"{selected.name}\" 下更新了 {count} 个 Text 字体大小 +2");
- }
- }
|