Skip to content

Commit 9119542

Browse files
author
BlackSpiral15
committed
Added MonoBehaviour entry inspector
Now we can see a file entry for each broken script
1 parent cda980a commit 9119542

File tree

3 files changed

+131
-24
lines changed

3 files changed

+131
-24
lines changed

Assets/DeadScriptsSearcher/Scripts/DeadScripts.cs

Lines changed: 50 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,43 @@
66
using UnityEditor;
77
namespace Spiral.EditorTools.DeadScriptsSearcher
88
{
9-
public struct DeadGUID
9+
public class DeadGID
1010
{
11+
public ulong gid;
12+
public bool showInfo;
13+
public string entry;
14+
}
15+
16+
public class DeadGUID
17+
{
18+
/// <summary>
19+
/// GUID, ассоциированный со скриптом
20+
/// </summary>
1121
public string guid;
22+
23+
/// <summary>
24+
/// Все мёртвые объекты со скриптом этого вида
25+
/// </summary>
1226
public List<ObjectID> oids;
27+
28+
/// <summary>
29+
/// Все MonoBehaviour со скриптом этого вида
30+
/// </summary>
31+
public List<DeadGID> gids;
32+
33+
34+
// EDITOR WINDOW STUFF
35+
public bool showInfo;
1336
}
1437

1538
public class DeadScripts
1639
{
1740
public bool debug = true;
18-
1941
public List<ObjectID> deadOIDs { get; private set; } = new List<ObjectID>();
2042
public List<DeadGUID> deadGUIDs { get; private set; } = new List<DeadGUID>();
21-
22-
2343
private SceneFile sceneFile = null;
2444

45+
// PROPERTIES -----------------------------------------------------------------------------
2546
public bool sceneFileLoaded
2647
{
2748
get
@@ -34,6 +55,7 @@ public bool sceneFileLoaded
3455

3556
public bool isDirty { get { return SceneManager.GetActiveScene().isDirty; } }
3657

58+
// FUNCTIONALITY --------------------------------------------------------------------------
3759
public void SelectDeads()
3860
{
3961
ObjectID.Select(deadOIDs);
@@ -114,20 +136,40 @@ public void SearchForDeads()
114136
if (string.IsNullOrEmpty(guid)) // GUID не был найден
115137
continue;
116138

139+
// GUID найден, создаём учётку для скрипта
140+
DeadGID deadGID = new DeadGID
141+
{
142+
gid = gid,
143+
showInfo = false
144+
};
145+
List<string> entryList = sceneFile.ComponentInfo(gid);
146+
string entry = "";
147+
for (int e = 0; e < entryList.Count; e++)
148+
{
149+
entry += entryList[e];
150+
if (e != entryList.Count - 1) entry += "\n";
151+
}
152+
deadGID.entry = entry;
153+
154+
// проверяем, есть GUID в списке или нет
117155
int guidIDX = deadGUIDs.FindIndex(x => x.guid == guid);
118-
if (guidIDX >= 0)
156+
if (guidIDX >= 0) // добавляем новый объект и новый компонент к уже существующему GUID
119157
{
120158
deadGUIDs[guidIDX].oids.Add(oid);
159+
deadGUIDs[guidIDX].gids.Add(deadGID);
121160
}
122-
else
161+
else // создаём новую GUID-учёткуы
123162
{
124163
DeadGUID deadGUID = new DeadGUID
125164
{
126165
guid = guid,
127-
oids = new List<ObjectID>()
166+
oids = new List<ObjectID>(),
167+
gids = new List<DeadGID>(),
168+
showInfo = false,
128169
};
129-
deadGUID.oids.Add(oid);
130170
deadGUIDs.Add(deadGUID);
171+
deadGUID.oids.Add(oid);
172+
deadGUID.gids.Add(deadGID);
131173
}
132174
}
133175
}

Assets/DeadScriptsSearcher/Scripts/DeadWindow.cs

Lines changed: 61 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace Spiral.EditorTools.DeadScriptsSearcher
88
{
99
public class DeadWindow : EditorWindow
1010
{
11-
private readonly DeadScripts deadscript = new DeadScripts();
11+
private readonly DeadScripts deadscript = new DeadScripts() { debug = false };
1212
public Local lang = Local.RU;
1313

1414
// LOCALIZATION ===========================================================================
@@ -99,7 +99,7 @@ public class DeadWindow : EditorWindow
9999
// en
100100
"Unique GUIDs found:"
101101
);
102-
private readonly static LocalString strShowDeadGUIDs = new LocalString(
102+
private readonly static LocalString strShowList = new LocalString(
103103
// ru
104104
"Показать/Скрыть список",
105105
// en
@@ -110,11 +110,16 @@ public class DeadWindow : EditorWindow
110110
"Объектов",
111111
// en
112112
"Objects count");
113-
private readonly static LocalString strSelectOnScene = new LocalString(
113+
private readonly static LocalString strSelectObjects = new LocalString(
114114
// ru
115-
"Выбрать на сцене",
115+
"Выделить все объекты с этим скриптом",
116116
// en
117-
"Select on the scene");
117+
"Select all objects with this script");
118+
private readonly static LocalString strSelectObject = new LocalString(
119+
// ru
120+
"Выделить объект",
121+
// en
122+
"Select target object");
118123
#endregion
119124

120125
// MENU INITIALIZATION ====================================================================
@@ -213,7 +218,7 @@ private void ShowDeadGUIDs()
213218
{
214219
EditorGUI.indentLevel += 1;
215220
foldoutDeads = EditorGUILayout.Foldout(foldoutDeads,
216-
strShowDeadGUIDs.Read(lang),
221+
strShowList.Read(lang),
217222
true, EditorStyles.foldout);
218223
EditorGUI.indentLevel -= 1;
219224
}
@@ -227,19 +232,58 @@ private void ShowDeadGUIDs()
227232
for (int i = 0; i < deadscript.deadGUIDs.Count; i++)
228233
{
229234
DeadGUID dead = deadscript.deadGUIDs[i];
235+
DrawDeadGUIDEntry(dead);
236+
}
237+
}
238+
EditorGUILayout.EndVertical();
239+
}
240+
241+
private void DrawDeadGUIDEntry(DeadGUID dead)
242+
{
243+
GUI.color = new Color(0.5f, 0.5f, 0.5f);
244+
EditorGUILayout.BeginVertical(EditorStyles.helpBox);
245+
GUI.color = defaultColor;
246+
247+
EditorGUILayout.SelectableLabel($"GUID: {dead.guid}", GUILayout.MinWidth(250));
230248

231-
EditorGUILayout.BeginVertical(EditorStyles.helpBox);
232-
EditorGUILayout.LabelField($"GUID #{i}", EditorStyles.miniBoldLabel);
233-
EditorGUILayout.SelectableLabel($"{dead.guid}", EditorStyles.label);
234-
EditorGUILayout.LabelField($"{strDeadObjectsCount.Read(lang)}: {dead.oids.Count}",
235-
EditorStyles.miniBoldLabel);
236-
if (GUILayout.Button(strSelectOnScene.Read(lang)))
249+
string strDeadCount = $"{strDeadObjectsCount.Read(lang)}: {dead.oids.Count}";
250+
251+
dead.showInfo = EditorGUILayout.Foldout(dead.showInfo, strDeadCount);
252+
if (dead.showInfo)
253+
{
254+
for (int i = 0; i < dead.gids.Count; i++)
255+
{
256+
var dgid = dead.gids[i];
257+
var dgidID = dgid.gid;
258+
259+
string strGID = $"{dgidID}";
260+
string strButtonName = $"#{i} MonoBehaviour ID: {strGID}";
261+
if (EditorGUILayout.DropdownButton(new GUIContent(strButtonName), FocusType.Passive))
262+
{
263+
dgid.showInfo = !dgid.showInfo;
264+
}
265+
if (dgid.showInfo)
237266
{
238-
ObjectID.Select(dead.oids);
267+
EditorGUILayout.BeginVertical(EditorStyles.helpBox);
268+
EditorGUILayout.SelectableLabel(strGID);
269+
if (GUILayout.Button(strSelectObject.Read(lang)))
270+
{
271+
Selection.objects = new Object[1] { dead.oids[i].gameObject };
272+
}
273+
GUI.enabled = false;
274+
EditorGUILayout.TextArea(dgid.entry);
275+
GUI.enabled = true;
276+
EditorGUILayout.Space();
277+
EditorGUILayout.EndVertical();
239278
}
240-
EditorGUILayout.EndVertical();
241279
}
242280
}
281+
282+
if (GUILayout.Button(strSelectObjects.Read(lang)))
283+
{
284+
ObjectID.Select(dead.oids);
285+
}
286+
243287
EditorGUILayout.EndVertical();
244288
}
245289

@@ -248,8 +292,10 @@ private void ShowDeadGUIDs()
248292
// Editor Window's Mono
249293
//=========================================================================================
250294
Vector2 scrollPos;
295+
Color defaultColor = Color.white;
251296
private void OnGUI()
252297
{
298+
defaultColor = GUI.color;
253299
switch (lang)
254300
{
255301
case Local.RU:
@@ -275,6 +321,7 @@ private void OnGUI()
275321
EditorGUILayout.EndScrollView();
276322

277323
EditorGUILayout.EndVertical();
324+
GUI.color = defaultColor;
278325
}
279326
}
280327
}

Assets/DeadScriptsSearcher/Scripts/SceneFile.cs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,24 @@ public int IndexOfComponent(ulong componentGID)
111111
return file.FindIndex(x => x.Contains($"&{componentGID}"));
112112
}
113113

114+
public List<string> ComponentInfo(ulong componentGID)
115+
{
116+
int cursor = IndexOfComponent(componentGID);
117+
if (cursor < 0) return null;
118+
List<string> output = new List<string>();
119+
string currentLine = file[cursor];
120+
output.Add(currentLine);
121+
cursor++;
122+
while (cursor < count)
123+
{
124+
currentLine = file[cursor];
125+
if (currentLine.Contains(unitSeparator)) { break; }
126+
output.Add(currentLine);
127+
cursor++;
128+
}
129+
return output;
130+
}
131+
114132
/// <summary>
115133
/// Выуживает все GID компонентов с объекта
116134
/// </summary>
@@ -149,7 +167,7 @@ public string GetGUID(ulong componentGID, bool debug)
149167
return string.Empty;
150168
}
151169

152-
int eof = file.Count - 1;
170+
int eof = count - 1;
153171
cursor += 2;
154172
bool mscriptFound = false;
155173
while (cursor < eof)
@@ -189,7 +207,7 @@ private List<ulong> GetComponentsGIDs(int fromIDX, bool debug)
189207
string currentLine; // читалка строки
190208
int cursor = fromIDX; // текущая позиция в файле
191209

192-
int eofIDX = file.Count;
210+
int eofIDX = count;
193211

194212
List<ulong> gids = new List<ulong>();
195213

0 commit comments

Comments
 (0)