54 lines
1.3 KiB
C#
54 lines
1.3 KiB
C#
using UnityEditor;
|
|
using UnityEngine;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
public class FindMissingPrefabs : EditorWindow
|
|
{
|
|
[MenuItem("Tools/Find Missing Prefabs")]
|
|
static void Init()
|
|
{
|
|
GetWindow<FindMissingPrefabs>("Find Missing Prefabs").Show();
|
|
}
|
|
|
|
private List<GameObject> missingPrefabs = new List<GameObject>();
|
|
|
|
void OnGUI()
|
|
{
|
|
if (GUILayout.Button("Find Missing Prefabs in Scene"))
|
|
{
|
|
FindMissing();
|
|
}
|
|
|
|
if (missingPrefabs.Count > 0)
|
|
{
|
|
GUILayout.Label("Missing Prefabs Found:", EditorStyles.boldLabel);
|
|
foreach (var obj in missingPrefabs.Take(32))
|
|
{
|
|
if (GUILayout.Button(obj.name))
|
|
{
|
|
Selection.activeGameObject = obj;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
GUILayout.Label("No missing prefabs found.");
|
|
}
|
|
}
|
|
|
|
void FindMissing()
|
|
{
|
|
missingPrefabs.Clear();
|
|
GameObject[] allObjects = GameObject.FindObjectsOfType<GameObject>();
|
|
|
|
foreach (GameObject obj in allObjects)
|
|
{
|
|
PrefabAssetType prefabType = PrefabUtility.GetPrefabAssetType(obj);
|
|
if (prefabType == PrefabAssetType.MissingAsset)
|
|
{
|
|
missingPrefabs.Add(obj);
|
|
}
|
|
}
|
|
}
|
|
} |