====== Assets以下のUILabelに設定されたFontを一括変更する(NGUI対応) ====== 「Assets/Resources/Prefabs」以下のUILabelに設定されたFontを一括で設定できるツールです。Editor拡張で作成。 using UnityEngine; using UnityEditor; using System.Collections; using System.Collections.Generic; public class FontReplace : EditorWindow { private UIFont font; [MenuItem("Tools/Replace Font")] public static void ReplaceFont() { EditorWindow.GetWindow(typeof(FontReplace)).Show(); } void OnGUI() { font = EditorGUILayout.ObjectField("UIFont", font, typeof(UIFont), true) as UIFont; if (font != null) { if (GUILayout.Button("Replace font in all assets")) { string title = "Replacing [" + font.name + "]"; EachAsset (title,font); } } } private static void EachAsset(string _title, UIFont _font) { string[] sarchDir = { "Assets/Resources/Prefabs"}; string[] guids = AssetDatabase.FindAssets("", sarchDir); for (int ii = 0; ii < guids.Length; ii++) { string guid = guids [ii]; string guidPath = AssetDatabase.GUIDToAssetPath(guid); EditorUtility.DisplayProgressBar(_title, guidPath, (float)ii / (float)guids.Length); GameObject go = AssetDatabase.LoadAssetAtPath(guidPath); if(go != null) { List uiLabelList = go.GetComponentsInParentAndChildren (); for (int jj = 0; jj < uiLabelList.Count; jj++) { UILabel uiLabel = uiLabelList[jj]; if (uiLabel != null) { uiLabel.bitmapFont = _font; EditorUtility.SetDirty(uiLabel); } } AssetDatabase.SaveAssets(); } } EditorUtility.ClearProgressBar(); } public static class GameObjectExtension { public static T GetComponentInParentAndChildren(this GameObject gameObject) where T : UnityEngine.Component { if(gameObject.GetComponentInParent() != null) { return gameObject.GetComponentInParent(); } if(gameObject.GetComponentInChildren() != null) { return gameObject.GetComponentInChildren(); } return gameObject.GetComponent(); } public static List GetComponentsInParentAndChildren(this GameObject gameObject) where T : UnityEngine.Component { List _list = new List (gameObject.GetComponents ()); _list.AddRange (new List (gameObject.GetComponentsInChildren ())); _list.AddRange (new List (gameObject.GetComponentsInParent ())); return _list; } } }