本文实现批量更换字体功能,实现代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
using UnityEngine; using System.Collections; using UnityEditor; using UnityEngine.UI; public class ChangeFontWindow : EditorWindow { [MenuItem("Tools/批量更换字体")] public static void Open() { EditorWindow.GetWindow(typeof(ChangeFontWindow), true); } static Font fromChangeFont; static Font toChangeFont; void OnGUI() { fromChangeFont = (Font)EditorGUILayout.ObjectField("原字体", fromChangeFont, typeof(Font), true, GUILayout.MinWidth(100)); toChangeFont = (Font)EditorGUILayout.ObjectField("目标字体", toChangeFont, typeof(Font), true, GUILayout.MinWidth(100)); if (GUILayout.Button("确认更换")) { Change(); } } public static void Change() { if (Selection.objects == null || Selection.objects.Length == 0) return; Object[] labels = Selection.GetFiltered(typeof(Text), SelectionMode.Deep); foreach (Object item in labels) { Text label = (Text)item; if (label.font == fromChangeFont) { label.font = toChangeFont; Debug.Log(item.name + ":" + label.text); EditorUtility.SetDirty(item); } } } } |
- 本文固定链接: http://www.u3d8.com/?p=1979
- 转载请注明: 网虫虫 在 u3d8.com 发表过