unity中检索当前文件夹下所有物体的某个组件工具

15 篇文章 0 订阅
13 篇文章 0 订阅

工具 在project视图中创建中点击选项  检索当前文件夹下所有物体的某个组件  代码用例是检索用到了UIDepth或UIEffectDepth

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System.IO;
public class GetComponenTools : MonoBehaviour {
	// 在菜单来创建 选项 , 点击该选项执行搜索代码
    [MenuItem("Assets/GetComponentTools/读取预制体包括子孙物体的组件")]
    static void CheckSceneSetting()
    {
		string guid = Selection.assetGUIDs[0];
        var selectPath = AssetDatabase.GUIDToAssetPath(guid);
        List<string> dirs = new List<string>();
        GetDirs(selectPath, ref dirs);
    }
    //参数1 为要查找的总路径, 参数2 保存路径
    private static void GetDirs(string dirPath, ref List<string> dirs)
    {
        foreach (string path in Directory.GetFiles(dirPath))
        {
            // Debug.Log(path);
            //获取所有文件夹中包含后缀为 .prefab 的路径
            if (System.IO.Path.GetExtension(path) == ".prefab" && path.IndexOf(@"UI\Slots") == -1)
            {
                dirs.Add(path.Substring(path.IndexOf("Asset")));
				string final_path = path.Substring(path.IndexOf("Asset")).Replace(@"\", "/");
				GameObject prefab = AssetDatabase.LoadAssetAtPath(final_path, typeof(System.Object)) as GameObject;
				// Debug.Log(final_path);
				if (prefab.transform.GetComponent<UIDepth>() || prefab.transform.GetComponent<UIEffectDepth>())
				{
                    Debug.Log("<color=#00EEEE>" + prefab + "</color>"+"用到了UIDepth或UIEffectDepth");
				}
                foreach(Transform child in prefab.GetComponentsInChildren<Transform>(true))
                {
                    if (child.GetComponent<UIDepth>() || child.GetComponent<UIEffectDepth>())
                    {
                        Debug.Log("父物体名字:" +"<color=#00EEEE>" + prefab + "</color>" +"子物体名字为:" +"<color=#FF6A6A>" + child + "</color>");
                    }
                }
            }
        }         
        if (Directory.GetDirectories(dirPath).Length > 0)  //遍历所有文件夹
        {
            foreach (string path in Directory.GetDirectories(dirPath))
            {
                GetDirs(path, ref dirs);
            }
        }
    }

}

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值