3
3
// **************************************************************** //
4
4
//
5
5
// Copyright (c) RimuruDev. All rights reserved.
6
- // Contact me:
6
+ // Contact:
7
7
// - Gmail: rimuru.dev@gmail.com
8
8
// - GitHub: https://github.com/RimuruDev
9
9
// - LinkedIn: https://www.linkedin.com/in/rimuru/
@@ -25,30 +25,37 @@ public static void ShowWindow() =>
25
25
private void OnGUI ( )
26
26
{
27
27
if ( GUILayout . Button ( "Find Missing Scripts in Scene" ) )
28
- {
29
28
FindMissingScriptsInScene ( ) ;
30
- }
31
29
32
30
if ( GUILayout . Button ( "Delete All Missing Scripts in Scene" ) )
33
- {
34
31
DeleteAllMissingScriptsInScene ( ) ;
35
- }
36
32
37
33
if ( GUILayout . Button ( "Find Missing Scripts in Prefabs" ) )
38
- {
39
34
FindMissingScriptsInPrefabs ( ) ;
40
- }
41
35
}
42
36
37
+ private static GameObject [ ] FindGameObjects ( bool includeInactive = true )
38
+ {
39
+ #if UNITY_6000_0_OR_NEWER
40
+ var inactiveMode = includeInactive
41
+ ? FindObjectsInactive . Include
42
+ : FindObjectsInactive . Exclude ;
43
+
44
+ return Object . FindObjectsByType < GameObject > ( inactiveMode , FindObjectsSortMode . InstanceID ) ;
45
+ #else
46
+ return Object . FindObjectsOfType < GameObject > ( includeInactive ) ;
47
+ #endif
48
+ }
49
+
50
+
43
51
private static void FindMissingScriptsInScene ( )
44
52
{
45
- var objects = FindObjectsOfType < GameObject > ( true ) ;
53
+ var objects = FindGameObjects ( ) ;
46
54
var missingCount = 0 ;
47
55
48
56
foreach ( var go in objects )
49
57
{
50
58
var components = go . GetComponents < Component > ( ) ;
51
-
52
59
foreach ( var component in components )
53
60
{
54
61
if ( component == null )
@@ -66,13 +73,12 @@ private static void FindMissingScriptsInScene()
66
73
67
74
private static void DeleteAllMissingScriptsInScene ( )
68
75
{
69
- var objects = FindObjectsOfType < GameObject > ( true ) ;
76
+ var objects = FindGameObjects ( ) ;
70
77
var removedCount = 0 ;
71
78
72
79
foreach ( var go in objects )
73
80
{
74
81
var components = go . GetComponents < Component > ( ) ;
75
-
76
82
foreach ( var component in components )
77
83
{
78
84
if ( component == null )
@@ -119,7 +125,6 @@ private static void FindMissingScriptsInPrefabs()
119
125
private static string GetFullPath ( GameObject go )
120
126
{
121
127
var path = "/" + go . name ;
122
-
123
128
while ( go . transform . parent != null )
124
129
{
125
130
go = go . transform . parent . gameObject ;
0 commit comments