源战役客户端
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 
 

87 строки
3.4 KiB

using UnityEngine;
using UnityEditor;
using System;
using System.Collections.Generic;
using UnityEngine.Assertions;
using UnityEngine.SceneManagement;
using UnityEditor.SceneManagement;
using UnityEngine.Internal;
using System.IO;
using System.Linq;
public class SelectMaterialrDependencies : EditorWindow
{
Vector2 scrollPos = Vector2.zero;
static private List<string> foundedMaterialResources = new List<string>(); //所有使用资源
[MenuItem("Assets/查找Material引用", true)]
static bool SelectMaterialDependenciesAvailable()
{
return Selection.activeObject != null && Selection.activeObject.GetType() == typeof(Material);
}
[MenuItem("Assets/查找Material引用", false)]
public static void GetMaterialDependencies()
{
string path = AssetDatabase.GetAssetPath(Selection.activeObject);
GetMaterialDependencies(path);
}
public static void GetMaterialDependencies(string path)
{
foundedMaterialResources.Clear();
List<string> includeExtensions = new List<string>() { ".prefab" };
string[] files = Directory.GetFiles(Application.dataPath + "/LuaFramework/AssetBundleRes/scene/", "*.*", SearchOption.AllDirectories)
.Where(s => includeExtensions.Contains(Path.GetExtension(s).ToLower())).ToArray();
float count = 0;
foreach (string file in files)
{
count++;
EditorUtility.DisplayProgressBar("Processing...", "检索中....", count / files.Length);
string strFile = file.Substring(file.IndexOf("Asset")).Replace('\\', '/');
string[] dependenciesFiles = AssetDatabase.GetDependencies(strFile, false);
foreach (string depFile in dependenciesFiles)
{
if(path.Equals(depFile))
{
foundedMaterialResources.Add(strFile);
}
}
}
EditorUtility.ClearProgressBar();
if (foundedMaterialResources.Count == 0)
{
EditorUtility.DisplayDialog("搜索结果", "没有找到任何模型引用该Material", "确定");
}
else
{
EditorUtility.DisplayDialog("搜索结果", "有" + foundedMaterialResources.Count + "个模型使用了这个Material", "确定");
SelectMaterialrDependencies checkWin = (SelectMaterialrDependencies)EditorWindow.GetWindow<SelectMaterialrDependencies>(false, "模型搜索结果", true);
checkWin.autoRepaintOnSceneChange = true;
checkWin.Show();
}
}
void OnGUI()
{
ShowMaterialDependenciesWindow();
}
void ShowMaterialDependenciesWindow()
{
EditorGUILayout.BeginHorizontal();
GUI.backgroundColor = Color.green;
EditorGUILayout.EndHorizontal();
GUI.backgroundColor = Color.white;
scrollPos = EditorGUILayout.BeginScrollView(scrollPos);
foreach (var path in foundedMaterialResources)
{
EditorGUILayout.BeginHorizontal();
UnityEngine.Object t = (UnityEngine.Object)AssetDatabase.LoadAssetAtPath(path, typeof(UnityEngine.Object));
EditorGUILayout.ObjectField(t, typeof(UnityEngine.Object), false);
GUI.backgroundColor = Color.green;
GUI.backgroundColor = Color.white;
EditorGUILayout.EndHorizontal();
}
EditorGUILayout.EndScrollView();
}
}