-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCleanScript.cs
34 lines (28 loc) · 1.12 KB
/
CleanScript.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
using UnityEditor;
using UnityEngine;
namespace CodeBase.Editor
{
public class FindMissingScriptsRecursivelyAndRemove : EditorWindow
{
[MenuItem("Auto/Remove Missing Scripts Recursively")]
private static void FindAndRemoveMissingInSelected()
{
var deepSelection = EditorUtility.CollectDeepHierarchy(Selection.gameObjects);
var compCount = 0;
var goCount = 0;
foreach (var o in deepSelection)
{
if (o is not GameObject go)
continue;
var count = GameObjectUtility.GetMonoBehavioursWithMissingScriptCount(go);
if (count <= 0)
continue;
Undo.RegisterCompleteObjectUndo(go, "Remove missing scripts");
GameObjectUtility.RemoveMonoBehavioursWithMissingScript(go);
compCount += count;
goCount++;
}
Debug.Log($"Found and removed {compCount} missing scripts from {goCount} GameObjects");
}
}
}