本文主要是介绍Unity3D 【编辑器扩展】一键批量修改预设UGUI Text字体,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
我们做项目的时候经常会遇到要换个字体的工作情况,比如美工同学觉着字体不好看或者要做其它语言版本什么的。遇到这种情况我们总不能一个标签一个标签的去找到它们把字体换了,累不累就不说了,万一漏了也是麻烦事。
转载请保留原文链接:http://blog.csdn.net/andyhebear/article/details/51393259
- using UnityEngine;
- using UnityEngine.UI;
- using UnityEditor;
-
- using System.Collections;
- using System.Collections.Generic;
-
-
- public class ChangeFontWindow : EditorWindow {
-
- static ChangeFontWindow() {
-
-
- }
-
- [MenuItem("Window/Change Font")]
- private static void ShowWindow() {
- ChangeFontWindow cw= EditorWindow.GetWindow<ChangeFontWindow>(true, "Window/Change Font");
-
- }
- Font toFont = new Font("Arial");
- static Font toChangeFont;
- FontStyle toFontStyle;
- static FontStyle toChangeFontStyle;
- private void OnGUI() {
- GUILayout.Space(10);
- GUILayout.Label("目标字体:");
- toFont = (Font)EditorGUILayout.ObjectField(toFont, typeof(Font), true, GUILayout.MinWidth(100f));
- toChangeFont = toFont;
- GUILayout.Space(10);
- GUILayout.Label("类型:");
- toFontStyle = (FontStyle)EditorGUILayout.EnumPopup(toFontStyle, GUILayout.MinWidth(100f));
- toChangeFontStyle = toFontStyle;
- 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;
- label.font = toChangeFont;
- label.fontStyle = toChangeFontStyle;
-
- Debug.Log(item.name + ":" + label.text);
-
- EditorUtility.SetDirty(item);
- }
- }
- private void OnEnable() {
- }
-
- private void OnDisable() {
- }
-
-
-
- private void Update() {
- }
-
- private void OnDestroy() {
- }
-
- }
这篇关于Unity3D 【编辑器扩展】一键批量修改预设UGUI Text字体的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!