zoukankan      html  css  js  c++  java
  • Unity3d中如何查找一个脚本被挂在那些预设上面?

    用一个脚本函数可以获取到选择的脚本文件被哪些预设和场景引用

    [MenuItem("Assets/Tool/GetReference")]
     static void GetReference()
       {
            string target = "";
            if (Selection.activeObject != null)
                target = AssetDatabase.GetAssetPath(Selection.activeObject);
            if (string.IsNullOrEmpty(target))
                return;
            string[] files = Directory.GetFiles(Application.dataPath, "*.prefab", SearchOption.AllDirectories);
            string[] scene = Directory.GetFiles(Application.dataPath, "*.unity", SearchOption.AllDirectories);
            
            List<Object> filelst = new List<Object>();
            for (int i = 0; i < files.Length; i++)
            {
                string[] source = AssetDatabase.GetDependencies(new string[] { files[i].Replace(Application.dataPath, "Assets") });
                for (int j = 0; j < source.Length; j++)
                {
                    if (source[j] == target)
                        filelst.Add(AssetDatabase.LoadMainAssetAtPath(files[i].Replace(Application.dataPath, "Assets")));
                }
            }
            for (int i = 0; i < scene.Length; i++)
            {
                string[] source = AssetDatabase.GetDependencies(new string[] { scene[i].Replace(Application.dataPath, "Assets") });
                for (int j = 0; j < source.Length; j++)
                {
                    if (source[j] == target)
                        filelst.Add(AssetDatabase.LoadMainAssetAtPath(scene[i].Replace(Application.dataPath, "Assets")));
                }
            }
            Selection.objects = filelst.ToArray();
        }
    

      

    我爱学习,学习使我快乐。
  • 相关阅读:
    ILM --interface logic model
    dbGet net trace instant pin
    LIST 列表
    Getopt::Long
    TCL Strings
    MBA 报考
    英语 口译考试
    微服务了解
    解析微服务架构(三):微服务重构应用及IBM解决方案
    解析微服务架构(二):融入微服务的企业集成架构
  • 原文地址:https://www.cnblogs.com/kerven/p/7450390.html
Copyright © 2011-2022 走看看