AkiraPixelWind/Assets/Scripts/Editor/ProjectTools/MyFindMissingWindow.cs

111 lines
3.9 KiB
C#
Raw Normal View History

2022-12-29 18:20:40 +08:00
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System.Linq;
public class MyFindMissingWindow : EditorWindow
{
#if UNITY_EDITOR
[MenuItem("<22><>Ŀ<EFBFBD><C4BF><EFBFBD><EFBFBD>/<2F><>Դ<EFBFBD><D4B4><EFBFBD><EFBFBD>/<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><CAA7><EFBFBD>õ<EFBFBD><C3B5><EFBFBD>Դ")]
static void ShowWindow()
{
GetWindow<MyFindMissingWindow>("<22><><EFBFBD><EFBFBD>Missing<6E><67>Դ").Show();
Find();
}
static Dictionary<Object, List<Object>> prefabs = new Dictionary<Object, List<Object>>();
static Dictionary<Object, List<string>> refPaths = new Dictionary<Object, List<string>>();
//Ѱ<><D1B0>missing<6E><67><EFBFBD><EFBFBD>Դ
static void Find()
{
string[] paths = AssetDatabase.GetAllAssetPaths();
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>prefab<61><62>Դ
var gos = paths.Where(path => path.EndsWith("prefab")).Select(path => AssetDatabase.LoadAssetAtPath<GameObject>(path));
foreach (var item in gos)
{
GameObject go = item as GameObject;
if (go == null)
{
continue;
}
Component[] cps = go.GetComponentsInChildren<Component>(true);
foreach (var cp in cps)
{
if (cp == null) //<2F><><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>
{
if (!prefabs.ContainsKey(go)) prefabs.Add(go, new List<Object>());
prefabs[go].Add(cp);
}
else //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>
{
SerializedObject so = new SerializedObject(cp);
SerializedProperty iterator = so.GetIterator();
//<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
while (iterator.NextVisible(true))
{
if (iterator.propertyType == SerializedPropertyType.ObjectReference)
{
//<2F><><EFBFBD>ö<EFBFBD><C3B6><EFBFBD><EFBFBD><EFBFBD>null <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>ID<49><44><EFBFBD><EFBFBD>0 ˵<><CBB5><EFBFBD><EFBFBD>ʧ<EFBFBD><CAA7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if (iterator.objectReferenceValue == null && iterator.objectReferenceInstanceIDValue != 0)
{
if (!refPaths.ContainsKey(cp)) refPaths.Add(cp, new List<string>());
refPaths[cp].Add(iterator.propertyPath);
if (!prefabs.ContainsKey(go)) prefabs.Add(go, new List<Object>());
prefabs[go].Add(cp);
}
}
}
}
}
}
}
//<2F><><EFBFBD><EFBFBD>ֻ<EFBFBD>ǽ<EFBFBD><C7BD><EFBFBD><EFBFBD>ҽ<EFBFBD><D2BD><EFBFBD><EFBFBD><EFBFBD>ʾ
private Vector3 scroll = Vector3.zero;
private void OnGUI()
{
scroll = EditorGUILayout.BeginScrollView(scroll);
EditorGUILayout.BeginVertical();
foreach (var item in prefabs)
{
EditorGUILayout.BeginHorizontal();
EditorGUILayout.ObjectField(item.Key, typeof(GameObject), true, GUILayout.Width(200));
EditorGUILayout.BeginVertical();
foreach (var cp in item.Value)
{
EditorGUILayout.BeginHorizontal();
if (cp)
{
EditorGUILayout.ObjectField(cp, cp.GetType(), true, GUILayout.Width(200));
if (refPaths.ContainsKey(cp))
{
string missingPath = null;
foreach (var path in refPaths[cp])
{
missingPath += path + "|";
}
if (missingPath != null)
missingPath = missingPath.Substring(0, missingPath.Length - 1);
GUILayout.Label(missingPath);
}
}
else
{
GUILayout.Label("<22><>ʧ<EFBFBD>ű<EFBFBD><C5B1><EFBFBD>");
}
EditorGUILayout.EndHorizontal();
}
EditorGUILayout.EndVertical();
EditorGUILayout.EndHorizontal();
}
EditorGUILayout.EndVertical();
EditorGUILayout.EndScrollView();
}
#endif
}