using UnityEngine; using UnityEngine.UI; using UnityEditor; using System.Collections; using System.Collections.Generic; ///--------------------------------------------- /// /// フォント一括入れ替え /// ///--------------------------------------------- public class FontReplacer : EditorWindow { string[] sarchDir = { "Assets/Resources/Prefabs"}; private Font fontData; [MenuItem("Tools/Font/FontReplecer")] public static void GetWindow() { EditorWindow.GetWindow(typeof(FontReplacer)).Show(); } ///--------------------------------------------- /// /// 更新 /// ///--------------------------------------------- void OnGUI() { this.fontData = EditorGUILayout.ObjectField("Font", this.fontData, typeof(Font), true) as Font; if (this.fontData == null) { return; } if (GUILayout.Button("Replace font in all assets")) { Replace (this.fontData); } } ///--------------------------------------------- /// /// 更新 /// ///--------------------------------------------- private void Replace(Font _fontData) { string title = "Replacing [" + _fontData.name + "]"; string[] guids = AssetDatabase.FindAssets("", sarchDir); //string[] guids = AssetDatabase.FindAssets ("l:concrete"); bool isSave = false; 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 textList = GetComponentsInParentAndChildren (go); for (int jj = 0; jj < textList.Count; jj++) { Text textData = textList[jj]; if (textData != null) { textData.font = _fontData; EditorUtility.SetDirty(textData); } } isSave = true; } } if(isSave) { AssetDatabase.SaveAssets(); } EditorUtility.ClearProgressBar(); } private static List GetComponentsInParentAndChildren(GameObject target) where T : UnityEngine.Component { bool includeInactive = true; List _list = new List (target.GetComponents ()); _list.AddRange (new List (target.GetComponentsInChildren (includeInactive))); _list.AddRange (new List (target.GetComponentsInParent (includeInactive))); return _list; } }