Repository navigation
Expand file tree
/
Copy pathCEditorWindowFindMissingScripts.cs
More file actions
66 lines (60 loc) · 1.92 KB
/
Copy pathCEditorWindowFindMissingScripts.cs
File metadata and controls
66 lines (60 loc) · 1.92 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
//http://wiki.unity3d.com/index.php?title=FindMissingScripts
public class CEditorWindowFindMissingScripts : EditorWindow
{
static int go_count = 0, components_count = 0, missing_count = 0;
[MenuItem("Tools/Strix_Tools/FindMissingScripts")]
public static void ShowWindow()
{
GetWindow<CEditorWindowFindMissingScripts>("MissingScripts Finder");
}
public void OnGUI()
{
if (GUILayout.Button("Find Missing Scripts in All Object"))
{
FindInSelected();
}
}
private static void FindInSelected()
{
Transform[] arrTransform = FindObjectsOfType<Transform>();
go_count = 0;
components_count = 0;
missing_count = 0;
foreach (Transform pTransform in arrTransform)
{
FindInGO(pTransform.gameObject);
}
Debug.Log(string.Format("Searched {0} GameObjects, {1} components, found {2} missing", go_count, components_count, missing_count));
}
private static void FindInGO(GameObject g)
{
go_count++;
Component[] components = g.GetComponents<Component>();
for (int i = 0; i < components.Length; i++)
{
components_count++;
if (components[i] == null)
{
missing_count++;
string s = g.name;
Transform t = g.transform;
while (t.parent != null)
{
s = t.parent.name + "/" + s;
t = t.parent;
}
Debug.Log(s + " has an empty script attached in position: " + i, g);
}
}
// Now recurse through each child GO (if there are any):
foreach (Transform childT in g.transform)
{
//Debug.Log("Searching " + childT.name + " " );
FindInGO(childT.gameObject);
}
}
}
#endif