美术同学说,修改一个模型后,模型的引用找起来麻烦,而且场景使用光照贴图,改变一些Mesh的UV后,需要重新烘焙使用过这个模型的Scene场景。于是网上找了大佬们的博客,发现几乎都是转的一个人的,有一些问题。
于是自己照着写了一个检查脚本,将所有功能集中在一个脚本里,不需要额外操作,有几个特点:
1、网上代码使用了NGUI的BetterList和NGUIEditorTools.DrawHeader显示可折叠的窗口。那项目里没有用NGUI的同学呢?,于是将此部分方法从NGUI嫁接过来;
2、代码整理,添加显示Animator和Scene的功能,而不是只显示字符串。
3、核心操作是利用Unity查找依赖方法AssetDatabase.GetDependencies(),然后做一些筛选和显示。
效果如下:
))
{
textureList.Add(name);
}
else if (name.EndsWith(".mat"))
{
matList.Add(name);
}
else if (name.EndsWith(".shader"))
{
shaderList.Add(name);
}
else if (name.EndsWith(".ttf"))
{
fontList.Add(name);
}
else if (name.EndsWith(".anim"))
{
animList.Add(name);
}
else if (name.EndsWith(".controller"))
{
animTorList.Add(name);
}
Debug.Log("Dependence:" + name);
ShowProgress((float)i / (float)names.Length, names.Length, i);
i++;
}
string checkType = "t:Prefab t:Scene";
i = 0;
string[] allGuids = AssetDatabase.FindAssets(checkType, checkPaths);
foreach (string guid in allGuids)
{
string assetPath = AssetDatabase.GUIDToAssetPath(guid);
names = AssetDatabase.GetDependencies(new string[] { assetPath });
foreach (string name in names)
{
if (name.Equals(curPathName))
{
if (assetPath.EndsWith(".prefab"))
{
prefabList.Add(assetPath);
break;
}
else if (assetPath.ToLower().EndsWith(".unity"))
{
levelList.Add(assetPath);
break;
}
}
}
ShowProgress((float)i / (float)allGuids.Length, allGuids.Length, i);
i++;
}
dic.Add("prefab", prefabList);
dic.Add("fbx", fbxList);
dic.Add("cs", scriptList);
dic.Add("texture", textureList);
dic.Add("mat", matList);
dic.Add("shader", shaderList);
dic.Add("font", fontList);
dic.Add("level", levelList);
dic.Add("animTor", animTorList);
dic.Add("anim", animList);
EditorWindow.GetWindow(false, "Object Dependencies", true).Show();
if (FindReference.instance.dict != null) FindReference.instance.dict.Clear();
FindReference.instance.dict = dic;
EditorUtility.ClearProgressBar();
}
public bool DrawHeader(string text) { return DrawHeader(text, text, false, false); }
public bool DrawHeader(string text, string key, bool forceOn, bool minimalistic)
{
bool state = EditorPrefs.GetBool(key, true);
if (!minimalistic) GUILayout.Space(3f);
if (!forceOn && !state) GUI.backgroundColor = new Color(0.8f, 0.8f, 0.8f);
GUILayout.BeginHorizontal();
GUI.changed = false;
if (minimalistic)
{
if (state) text = "\u25BC" + (char)0x200a + text;
else text = "\u25BA" + (char)0x200a + text;
GUILayout.BeginHorizontal();
GUI.cOntentColor= EditorGUIUtility.isProSkin ? new Color(1f, 1f, 1f, 0.7f) : new Color(0f, 0f, 0f, 0.7f);
if (!GUILayout.Toggle(true, text, "PreToolbar2", GUILayout.MinWidth(20f))) state = !state;
GUI.cOntentColor= Color.white;
GUILayout.EndHorizontal();
}
else
{
text = "" + text + "";
if (state) text = "\u25BC " + text;
else text = "\u25BA " + text;
if (!GUILayout.Toggle(true, text, "dragtab", GUILayout.MinWidth(20f))) state = !state;
}
if (GUI.changed) EditorPrefs.SetBool(key, state);
if (!minimalistic) GUILayout.Space(2f);
GUILayout.EndHorizontal();
GUI.backgroundColor = Color.white;
if (!forceOn && !state) GUILayout.Space(3f);
return state;
}
public static void ShowProgress(float val, int total, int cur)
{
EditorUtility.DisplayProgressBar("Searching", string.Format("Checking ({0}/{1}), please wait...", cur, total), val);
}
}
欢迎交流经验,转载注明来自