Unity——Editor下遍历制定目录下Prefab

[MenuItem("Tools/检测Text字体设置是否规范")]
    public static void CheckTextFont()
    {
        string[] allPath = AssetDatabase.FindAssets("t:Prefab", new string[] {"Assets/GameResources/UI"});
        for (int i = 0; i < allPath.Length; i++)
        {
            string path = AssetDatabase.GUIDToAssetPath(allPath[i]);
            var obj = AssetDatabase.LoadAssetAtPath(path, typeof(GameObject)) as GameObject;
            if (obj!=null)
            {
                var texts = obj.GetComponentsInChildren();
                foreach (var text in texts)
                {
                    if (text.font.name == "RADIO" || text.font.name == "eurostile" || text.font.name == "Arial" )
                    {
                        Debug.Log("预制体:["+ obj.name+"] 的组件 ["+ text.name +"] 有误");
//                        break;
                    }
                }
            }
        }
    }

 

你可能感兴趣的:(UnityEditor)