Skip to content

Commit 32412fe

Browse files
authored
Updated for Unity 6000 and above.
1 parent 13cacbf commit 32412fe

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

Editor/MissingScriptsFinder.cs

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// **************************************************************** //
44
//
55
// Copyright (c) RimuruDev. All rights reserved.
6-
// Contact me:
6+
// Contact:
77
// - Gmail: rimuru.dev@gmail.com
88
// - GitHub: https://github.com/RimuruDev
99
// - LinkedIn: https://www.linkedin.com/in/rimuru/
@@ -25,30 +25,37 @@ public static void ShowWindow() =>
2525
private void OnGUI()
2626
{
2727
if (GUILayout.Button("Find Missing Scripts in Scene"))
28-
{
2928
FindMissingScriptsInScene();
30-
}
3129

3230
if (GUILayout.Button("Delete All Missing Scripts in Scene"))
33-
{
3431
DeleteAllMissingScriptsInScene();
35-
}
3632

3733
if (GUILayout.Button("Find Missing Scripts in Prefabs"))
38-
{
3934
FindMissingScriptsInPrefabs();
40-
}
4135
}
4236

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+
4351
private static void FindMissingScriptsInScene()
4452
{
45-
var objects = FindObjectsOfType<GameObject>(true);
53+
var objects = FindGameObjects();
4654
var missingCount = 0;
4755

4856
foreach (var go in objects)
4957
{
5058
var components = go.GetComponents<Component>();
51-
5259
foreach (var component in components)
5360
{
5461
if (component == null)
@@ -66,13 +73,12 @@ private static void FindMissingScriptsInScene()
6673

6774
private static void DeleteAllMissingScriptsInScene()
6875
{
69-
var objects = FindObjectsOfType<GameObject>(true);
76+
var objects = FindGameObjects();
7077
var removedCount = 0;
7178

7279
foreach (var go in objects)
7380
{
7481
var components = go.GetComponents<Component>();
75-
7682
foreach (var component in components)
7783
{
7884
if (component == null)
@@ -119,7 +125,6 @@ private static void FindMissingScriptsInPrefabs()
119125
private static string GetFullPath(GameObject go)
120126
{
121127
var path = "/" + go.name;
122-
123128
while (go.transform.parent != null)
124129
{
125130
go = go.transform.parent.gameObject;

0 commit comments

Comments
 (0)