Skip to content

Commit 368c377

Browse files
Added a script that find missing component on prefab and in scenes
1 parent 03ecf75 commit 368c377

File tree

5 files changed

+123
-1
lines changed

5 files changed

+123
-1
lines changed

Assets/MissingScriptFinder.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/MissingScriptFinder/Editor.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
using System.Collections;
2+
using System.Collections.Generic;
3+
using UnityEngine;
4+
using UnityEditor;
5+
using UnityEngine.SceneManagement;
6+
7+
public class FindMissingScripts: EditorWindow
8+
{
9+
[MenuItem("Content Extensions/Find Missing Component")]
10+
static public void FindMissing()
11+
{
12+
GetWindow<FindMissingScripts>();
13+
}
14+
15+
protected List<GameObject> _objectWithMissingScripts;
16+
protected Vector2 _scrollPosition;
17+
18+
private void OnEnable()
19+
{
20+
_objectWithMissingScripts = new List<GameObject>();
21+
_scrollPosition = Vector2.zero;
22+
}
23+
24+
private void OnGUI()
25+
{
26+
EditorGUILayout.BeginHorizontal();
27+
if (GUILayout.Button("Find in Assets"))
28+
FindInAssets();
29+
if (GUILayout.Button("Find in Current Scene"))
30+
FindInScenes();
31+
EditorGUILayout.EndHorizontal();
32+
33+
_scrollPosition = EditorGUILayout.BeginScrollView(_scrollPosition);
34+
35+
for (int i = 0; i < _objectWithMissingScripts.Count; ++i)
36+
{
37+
if (GUILayout.Button(_objectWithMissingScripts[i].name))
38+
{
39+
EditorGUIUtility.PingObject(_objectWithMissingScripts[i]);
40+
}
41+
}
42+
43+
EditorGUILayout.EndScrollView();
44+
}
45+
46+
void FindInAssets()
47+
{
48+
var assetGUIDs = AssetDatabase.FindAssets("t:GameObject");
49+
_objectWithMissingScripts.Clear();
50+
51+
Debug.Log("Testing " + assetGUIDs.Length + " GameObject in Assets");
52+
53+
foreach (string assetGuiD in assetGUIDs)
54+
{
55+
GameObject obj = AssetDatabase.LoadAssetAtPath<GameObject>(AssetDatabase.GUIDToAssetPath(assetGuiD));
56+
57+
RecursiveDepthSearch(obj);
58+
}
59+
}
60+
61+
void RecursiveDepthSearch(GameObject root)
62+
{
63+
Component[] components = root.GetComponents<Component>();
64+
foreach (Component c in components)
65+
{
66+
if (c == null)
67+
{
68+
if (!_objectWithMissingScripts.Contains(root))
69+
_objectWithMissingScripts.Add(root);
70+
}
71+
}
72+
73+
foreach (Transform t in root.transform)
74+
{
75+
RecursiveDepthSearch(t.gameObject);
76+
}
77+
}
78+
79+
void FindInScenes()
80+
{
81+
_objectWithMissingScripts.Clear();
82+
83+
for(int i= 0; i < SceneManager.sceneCount; ++i)
84+
{
85+
var rootGOs = SceneManager.GetSceneAt(i).GetRootGameObjects();
86+
87+
Debug.Log("Testing " + rootGOs.Length + " Gameobjects in scene " + i);
88+
89+
foreach (GameObject obj in rootGOs)
90+
{
91+
RecursiveDepthSearch(obj);
92+
}
93+
}
94+
}
95+
}

Assets/MissingScriptFinder/Editor/FindMissingScripts.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ProjectSettings/ProjectVersion.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
m_EditorVersion: 2018.1.0b13
1+
m_EditorVersion: 2018.1.0f2

0 commit comments

Comments
 (0)