源战役客户端
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

81 wiersze
3.2 KiB

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