源战役客户端
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

87 linhas
3.4 KiB

4 semanas atrás
  1. using UnityEngine;
  2. using UnityEditor;
  3. using System;
  4. using System.Collections.Generic;
  5. using UnityEngine.Assertions;
  6. using UnityEngine.SceneManagement;
  7. using UnityEditor.SceneManagement;
  8. using UnityEngine.Internal;
  9. using System.IO;
  10. using System.Linq;
  11. public class SelectMaterialrDependencies : EditorWindow
  12. {
  13. Vector2 scrollPos = Vector2.zero;
  14. static private List<string> foundedMaterialResources = new List<string>(); //所有使用资源
  15. [MenuItem("Assets/查找Material引用", true)]
  16. static bool SelectMaterialDependenciesAvailable()
  17. {
  18. return Selection.activeObject != null && Selection.activeObject.GetType() == typeof(Material);
  19. }
  20. [MenuItem("Assets/查找Material引用", false)]
  21. public static void GetMaterialDependencies()
  22. {
  23. string path = AssetDatabase.GetAssetPath(Selection.activeObject);
  24. GetMaterialDependencies(path);
  25. }
  26. public static void GetMaterialDependencies(string path)
  27. {
  28. foundedMaterialResources.Clear();
  29. List<string> includeExtensions = new List<string>() { ".prefab" };
  30. string[] files = Directory.GetFiles(Application.dataPath + "/LuaFramework/AssetBundleRes/scene/", "*.*", SearchOption.AllDirectories)
  31. .Where(s => includeExtensions.Contains(Path.GetExtension(s).ToLower())).ToArray();
  32. float count = 0;
  33. foreach (string file in files)
  34. {
  35. count++;
  36. EditorUtility.DisplayProgressBar("Processing...", "检索中....", count / files.Length);
  37. string strFile = file.Substring(file.IndexOf("Asset")).Replace('\\', '/');
  38. string[] dependenciesFiles = AssetDatabase.GetDependencies(strFile, false);
  39. foreach (string depFile in dependenciesFiles)
  40. {
  41. if(path.Equals(depFile))
  42. {
  43. foundedMaterialResources.Add(strFile);
  44. }
  45. }
  46. }
  47. EditorUtility.ClearProgressBar();
  48. if (foundedMaterialResources.Count == 0)
  49. {
  50. EditorUtility.DisplayDialog("搜索结果", "没有找到任何模型引用该Material", "确定");
  51. }
  52. else
  53. {
  54. EditorUtility.DisplayDialog("搜索结果", "有" + foundedMaterialResources.Count + "个模型使用了这个Material", "确定");
  55. SelectMaterialrDependencies checkWin = (SelectMaterialrDependencies)EditorWindow.GetWindow<SelectMaterialrDependencies>(false, "模型搜索结果", true);
  56. checkWin.autoRepaintOnSceneChange = true;
  57. checkWin.Show();
  58. }
  59. }
  60. void OnGUI()
  61. {
  62. ShowMaterialDependenciesWindow();
  63. }
  64. void ShowMaterialDependenciesWindow()
  65. {
  66. EditorGUILayout.BeginHorizontal();
  67. GUI.backgroundColor = Color.green;
  68. EditorGUILayout.EndHorizontal();
  69. GUI.backgroundColor = Color.white;
  70. scrollPos = EditorGUILayout.BeginScrollView(scrollPos);
  71. foreach (var path in foundedMaterialResources)
  72. {
  73. EditorGUILayout.BeginHorizontal();
  74. UnityEngine.Object t = (UnityEngine.Object)AssetDatabase.LoadAssetAtPath(path, typeof(UnityEngine.Object));
  75. EditorGUILayout.ObjectField(t, typeof(UnityEngine.Object), false);
  76. GUI.backgroundColor = Color.green;
  77. GUI.backgroundColor = Color.white;
  78. EditorGUILayout.EndHorizontal();
  79. }
  80. EditorGUILayout.EndScrollView();
  81. }
  82. }