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

[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();
    }

  Unity3d中如何查找一个脚本被挂在那些预设上面?

 

相关文章:

  • 2022-02-15
  • 2022-12-23
  • 2021-11-08
  • 2021-07-23
  • 2022-12-23
  • 2021-09-18
  • 2022-12-23
  • 2021-07-01
猜你喜欢
  • 2022-12-23
  • 2021-08-07
  • 2021-09-22
  • 2021-09-13
  • 2022-12-23
  • 2021-11-12
  • 2021-11-23
相关资源
相似解决方案