13
13
using UnityEditor ;
14
14
using UnityEngine ;
15
15
using UnityEditor . SceneManagement ;
16
- using System . Runtime . Remoting . Activation ;
17
16
18
17
namespace AbyssMoth
19
18
{
20
- [ Url ( "https://github.com/RimuruDev/Unity-MissingScriptsFinder" ) ]
21
19
public sealed class MissingScriptsFinder : EditorWindow
22
20
{
23
21
[ MenuItem ( "RimuruDev Tools/Find Missing Scripts" ) ]
@@ -28,16 +26,21 @@ private void OnGUI()
28
26
{
29
27
if ( GUILayout . Button ( "Find Missing Scripts in Scene" ) )
30
28
{
31
- FindMissingScripts ( ) ;
29
+ FindMissingScriptsInScene ( ) ;
32
30
}
33
31
34
- if ( GUILayout . Button ( "Delete All Missing Scripts" ) )
32
+ if ( GUILayout . Button ( "Delete All Missing Scripts in Scene " ) )
35
33
{
36
- DeleteAllMissingScripts ( ) ;
34
+ DeleteAllMissingScriptsInScene ( ) ;
35
+ }
36
+
37
+ if ( GUILayout . Button ( "Find Missing Scripts in Prefabs" ) )
38
+ {
39
+ FindMissingScriptsInPrefabs ( ) ;
37
40
}
38
41
}
39
42
40
- private static void FindMissingScripts ( )
43
+ private static void FindMissingScriptsInScene ( )
41
44
{
42
45
var objects = FindObjectsOfType < GameObject > ( true ) ;
43
46
var missingCount = 0 ;
@@ -58,12 +61,12 @@ private static void FindMissingScripts()
58
61
59
62
Debug . Log ( missingCount == 0
60
63
? "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>") ;
62
65
}
63
66
64
- private static void DeleteAllMissingScripts ( )
67
+ private static void DeleteAllMissingScriptsInScene ( )
65
68
{
66
- var objects = GameObject . FindObjectsOfType < GameObject > ( true ) ;
69
+ var objects = FindObjectsOfType < GameObject > ( true ) ;
67
70
var removedCount = 0 ;
68
71
69
72
foreach ( var go in objects )
@@ -74,20 +77,45 @@ private static void DeleteAllMissingScripts()
74
77
{
75
78
if ( component == null )
76
79
{
77
- Undo . RegisterCompleteObjectUndo ( go , "Remove Missing Scripts" ) ;
78
80
GameObjectUtility . RemoveMonoBehavioursWithMissingScript ( go ) ;
79
81
removedCount ++ ;
80
82
}
81
83
}
82
84
}
83
85
84
86
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>") ;
87
89
88
90
EditorSceneManager . MarkAllScenesDirty ( ) ;
89
91
}
90
92
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
+
91
119
private static string GetFullPath ( GameObject go )
92
120
{
93
121
var path = "/" + go . name ;
@@ -101,4 +129,4 @@ private static string GetFullPath(GameObject go)
101
129
return path ;
102
130
}
103
131
}
104
- }
132
+ }
0 commit comments