ユーザ用ツール

サイト用ツール

wiki:unity:asset:ngui:3.9:007

差分

この文書の現在のバージョンと選択したバージョンの差分を表示します。

この比較画面にリンクする

次のリビジョン
前のリビジョン
wiki:unity:asset:ngui:3.9:007 [2016/04/13 12:12]
step 作成
wiki:unity:asset:ngui:3.9:007 [2016/10/17 23:20] (現在)
step
ライン 1: ライン 1:
-====== Assets以下のUILabelに設定されたFontを一括変更する ======+====== Assets以下のUILabelに設定されたFontを一括変更する(NGUI対応) ​======
  
 「Assets/​Resources/​Prefabs」以下のUILabelに設定されたFontを一括で設定できるツールです。Editor拡張で作成。 「Assets/​Resources/​Prefabs」以下のUILabelに設定されたFontを一括で設定できるツールです。Editor拡張で作成。
  
  
-<​code>​+<​code ​csharp FontReplace.cs>
 using UnityEngine;​ using UnityEngine;​
 using UnityEditor;​ using UnityEditor;​
ライン 12: ライン 12:
 public class FontReplace : EditorWindow ​ public class FontReplace : EditorWindow ​
 { {
- private UIFont font;+    ​private UIFont font;
  
- [MenuItem("​Tools/​Replace Font"​)] +    ​[MenuItem("​Tools/​Replace Font"​)] 
- public static void ReplaceFont() { +    public static void ReplaceFont() { 
- EditorWindow.GetWindow(typeof(FontReplace)).Show();​ +        EditorWindow.GetWindow(typeof(FontReplace)).Show();​ 
- } +       
  
- void OnGUI() +    ​void OnGUI() 
-+    
- font = EditorGUILayout.ObjectField("​UIFont",​ font, typeof(UIFont),​ true) as UIFont; +        font = EditorGUILayout.ObjectField("​UIFont",​ font, typeof(UIFont),​ true) as UIFont; 
- if (font != null) { +        if (font != null) { 
- if (GUILayout.Button("​Replace font in all assets"​)) { +            if (GUILayout.Button("​Replace font in all assets"​)) { 
- string title = "​Replacing [" + font.name + "​]";​ +                string title = "​Replacing [" + font.name + "​]";​ 
- EachAsset (title,​font);​ +                EachAsset (title,​font);​ 
- +            
- +        
- }+    }
  
- private static void EachAsset(string _title, UIFont _font) +    ​private static void EachAsset(string _title, UIFont _font) 
- {         +    {         
-         string[] sarchDir = { "​Assets/​Resources/​Prefabs"​};​ +            string[] sarchDir = { "​Assets/​Resources/​Prefabs"​};​ 
- string[] guids = AssetDatabase.FindAssets("",​ sarchDir);+        string[] guids = AssetDatabase.FindAssets("",​ sarchDir);
         ​         ​
- for (int ii = 0; ii < guids.Length;​ ii++) +        ​for (int ii = 0; ii < guids.Length;​ ii++) 
- +        
- string guid = guids [ii]; +            string guid = guids [ii]; 
- string guidPath = AssetDatabase.GUIDToAssetPath(guid);​+            string guidPath = AssetDatabase.GUIDToAssetPath(guid);​
  
- EditorUtility.DisplayProgressBar(_title,​ guidPath, (float)ii / (float)guids.Length);​+            ​EditorUtility.DisplayProgressBar(_title,​ guidPath, (float)ii / (float)guids.Length);​
  
- GameObject go = AssetDatabase.LoadAssetAtPath<​GameObject>​(guidPath);​+            ​GameObject go = AssetDatabase.LoadAssetAtPath<​GameObject>​(guidPath);​
  
- if(go != null) +            ​if(go != null) 
- +            
- List<​UILabel>​ uiLabelList = go.GetComponentsInParentAndChildren <​UILabel>​ (); +                List<​UILabel>​ uiLabelList = go.GetComponentsInParentAndChildren <​UILabel>​ (); 
- for (int jj = 0; jj < uiLabelList.Count;​ jj++) +                for (int jj = 0; jj < uiLabelList.Count;​ jj++) 
- +                
- UILabel uiLabel = uiLabelList[jj];​ +                    UILabel uiLabel = uiLabelList[jj];​ 
- if (uiLabel != null) +                    if (uiLabel != null) 
- +                    
- uiLabel.bitmapFont = _font; +                        uiLabel.bitmapFont = _font; 
- EditorUtility.SetDirty(uiLabel);​ +                        EditorUtility.SetDirty(uiLabel);​ 
- +                    
- +                
- AssetDatabase.SaveAssets();​ +                AssetDatabase.SaveAssets();​ 
- +            
- +        
- EditorUtility.ClearProgressBar();​ +        EditorUtility.ClearProgressBar();​ 
-+    
-}+     
 +    public static class GameObjectExtension 
 +    { 
 +        public static T GetComponentInParentAndChildren<​T>​(this GameObject gameObject) where T : UnityEngine.Component 
 +        { 
 +            if(gameObject.GetComponentInParent<​T>​() != null) 
 +            { 
 +                return gameObject.GetComponentInParent<​T>​();​ 
 +            ​}
  
-public static class GameObjectExtension +            if(gameObject.GetComponentInChildren<​T>​() ​!= null) 
-+            
- public static T GetComponentInParentAndChildren<T>(this GameObject gameObjectwhere T : UnityEngine.Component +                ​return ​gameObject.GetComponentInChildren<T>(); 
-+            } 
- if(gameObject.GetComponentInParent<​T>​() ​!= null) +            return gameObject.GetComponent<​T>​();​ 
- { +        }
- return gameObject.GetComponentInParent<​T>​();​ +
- }+
  
- if(gameObject.GetComponentInChildren<​T>​() ​!= null) +        public static List<​T>​ GetComponentsInParentAndChildren<T>(this GameObject gameObjectwhere T : UnityEngine.Component 
- +        
- return gameObject.GetComponentInChildren<T>(); +            ​List<​T>​ _list = new List<T> (gameObject.GetComponents<T> ());
-+
- return ​gameObject.GetComponent<​T>​();​ +
- }+
  
- public static ​List<T> GetComponentsInParentAndChildren<T>(this GameObject ​gameObject) where T : UnityEngine.Component +            _list.AddRange (new List<​T>​ (gameObject.GetComponentsInChildren<​T> ​())); 
-+            ​_list.AddRange (new List<​T>​ (gameObject.GetComponentsInParent<T> ()));
- List<T> _list new List<​T>​ (gameObject.GetComponents<T> ());+
  
- _list.AddRange (new List<​T>​ (gameObject.GetComponentsInChildren<​T>​ ()))+            return ​_list; 
- _list.AddRange (new List<​T>​ (gameObject.GetComponentsInParent<​T>​ ()));+        } 
 +    } 
 +     
 +}
  
- return _list; 
- } 
-} 
 </​code>​ </​code>​
  
Permalink wiki/unity/asset/ngui/3.9/007.1460549569.txt.gz · 最終更新: 2016/04/13 12:12 by step

oeffentlich