内容へ移動
ユーザ用ツール
サイト用ツール
検索
ツール
文書の表示
以前のリビジョン
バックリンク
最近の変更
メディアマネージャー
サイトマップ
ログイン
>
現在位置:
Home
»
wiki
»
Unity
»
Tips
»
TextコンポーネントのFontを一括変更する(5.4.1f)
トレース:
wiki:unity:tips:206
この文書は読取専用です。文書のソースを閲覧することは可能ですが、変更はできません。もし変更したい場合は管理者に連絡してください。
====== TextコンポーネントのFontを一括変更する(5.4.1f) ====== ===== 概要 ===== 指定したディレクトリ内のPrefabに割り当てられているTextコンポーネントのFontを一括で変更できるEditor拡張です。 <code csharp Editor拡張> using UnityEngine; using UnityEngine.UI; using UnityEditor; using System.Collections; using System.Collections.Generic; ///--------------------------------------------- /// <summary> /// フォント一括入れ替え /// </summary> ///--------------------------------------------- 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(); } ///--------------------------------------------- /// <summary> /// 更新 /// </summary> ///--------------------------------------------- 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); } } ///--------------------------------------------- /// <summary> /// 更新 /// </summary> ///--------------------------------------------- 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<GameObject>(guidPath); if(go != null) { List<Text> textList = GetComponentsInParentAndChildren <Text> (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<T> GetComponentsInParentAndChildren<T>(GameObject target) where T : UnityEngine.Component { bool includeInactive = true; List<T> _list = new List<T> (target.GetComponents<T> ()); _list.AddRange (new List<T> (target.GetComponentsInChildren<T> (includeInactive))); _list.AddRange (new List<T> (target.GetComponentsInParent<T> (includeInactive))); return _list; } } </code>
Permalink
wiki/unity/tips/206.txt
· 最終更新: 2016/10/17 23:19 by
step
ページ用ツール
ログイン
文書の表示
文書の先頭へ
印刷
以前のリビジョン
バックリンク
最近の変更
メディアマネージャー
サイトマップ
oeffentlich