Skip to content

Commit 194b12a

Browse files
authored
Added Support Find Missing Scripts In Prefabs
1 parent b9a55ed commit 194b12a

File tree

1 file changed

+41
-13
lines changed

1 file changed

+41
-13
lines changed

Editor/MissingScriptsFinder.cs

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,9 @@
1313
using UnityEditor;
1414
using UnityEngine;
1515
using UnityEditor.SceneManagement;
16-
using System.Runtime.Remoting.Activation;
1716

1817
namespace AbyssMoth
1918
{
20-
[Url("https://github.com/RimuruDev/Unity-MissingScriptsFinder")]
2119
public sealed class MissingScriptsFinder : EditorWindow
2220
{
2321
[MenuItem("RimuruDev Tools/Find Missing Scripts")]
@@ -28,16 +26,21 @@ private void OnGUI()
2826
{
2927
if (GUILayout.Button("Find Missing Scripts in Scene"))
3028
{
31-
FindMissingScripts();
29+
FindMissingScriptsInScene();
3230
}
3331

34-
if (GUILayout.Button("Delete All Missing Scripts"))
32+
if (GUILayout.Button("Delete All Missing Scripts in Scene"))
3533
{
36-
DeleteAllMissingScripts();
34+
DeleteAllMissingScriptsInScene();
35+
}
36+
37+
if (GUILayout.Button("Find Missing Scripts in Prefabs"))
38+
{
39+
FindMissingScriptsInPrefabs();
3740
}
3841
}
3942

40-
private static void FindMissingScripts()
43+
private static void FindMissingScriptsInScene()
4144
{
4245
var objects = FindObjectsOfType<GameObject>(true);
4346
var missingCount = 0;
@@ -58,12 +61,12 @@ private static void FindMissingScripts()
5861

5962
Debug.Log(missingCount == 0
6063
? "No missing scripts found in the scene."
61-
: $"<color=magenta>Found {missingCount} GameObjects with missing scripts.</color>");
64+
: $"<color=magenta>Found {missingCount} GameObjects with missing scripts in the scene.</color>");
6265
}
6366

64-
private static void DeleteAllMissingScripts()
67+
private static void DeleteAllMissingScriptsInScene()
6568
{
66-
var objects = GameObject.FindObjectsOfType<GameObject>(true);
69+
var objects = FindObjectsOfType<GameObject>(true);
6770
var removedCount = 0;
6871

6972
foreach (var go in objects)
@@ -74,20 +77,45 @@ private static void DeleteAllMissingScripts()
7477
{
7578
if (component == null)
7679
{
77-
Undo.RegisterCompleteObjectUndo(go, "Remove Missing Scripts");
7880
GameObjectUtility.RemoveMonoBehavioursWithMissingScript(go);
7981
removedCount++;
8082
}
8183
}
8284
}
8385

8486
Debug.Log(removedCount == 0
85-
? "No missing scripts found to delete."
86-
: $"<color=magenta>Deleted {removedCount} missing scripts.</color>");
87+
? "No missing scripts found to delete in the scene."
88+
: $"<color=magenta>Deleted {removedCount} missing scripts in the scene.</color>");
8789

8890
EditorSceneManager.MarkAllScenesDirty();
8991
}
9092

93+
private static void FindMissingScriptsInPrefabs()
94+
{
95+
var prefabGUIDs = AssetDatabase.FindAssets("t:Prefab");
96+
var missingCount = 0;
97+
98+
foreach (var guid in prefabGUIDs)
99+
{
100+
var path = AssetDatabase.GUIDToAssetPath(guid);
101+
var prefab = AssetDatabase.LoadAssetAtPath<GameObject>(path);
102+
var components = prefab.GetComponentsInChildren<Component>(true);
103+
104+
foreach (var component in components)
105+
{
106+
if (component == null)
107+
{
108+
missingCount++;
109+
Debug.Log($"<color=yellow>Missing script found in Prefab: {path}</color>", prefab);
110+
}
111+
}
112+
}
113+
114+
Debug.Log(missingCount == 0
115+
? "No missing scripts found in any prefabs."
116+
: $"<color=magenta>Found {missingCount} prefabs with missing scripts.</color>");
117+
}
118+
91119
private static string GetFullPath(GameObject go)
92120
{
93121
var path = "/" + go.name;
@@ -101,4 +129,4 @@ private static string GetFullPath(GameObject go)
101129
return path;
102130
}
103131
}
104-
}
132+
}

0 commit comments

Comments
 (0)