mirror of
https://gitgud.io/AbstractConcept/rimworld-animation-studio.git
synced 2024-08-15 00:43:27 +00:00
bb2cc29393
commitaf4dab5546
Author: AbstractConcept <abstract.concept@mail.com> Date: Mon Oct 31 19:58:41 2022 -0500 Code refactor commite14a12f2ab
Author: AbstractConcept <abstract.concept@mail.com> Date: Mon Oct 31 00:44:53 2022 -0500 Code refactor commit5ca7e486f8
Author: AbstractConcept <abstract.concept@mail.com> Date: Fri Oct 28 19:52:58 2022 -0500 Code refactor commita55ba7b95b
Author: AbstractConcept <abstract.concept@mail.com> Date: Fri Oct 28 00:28:51 2022 -0500 Code refactor commit757badf4f6
Author: AbstractConcept <abstract.concept@mail.com> Date: Thu Oct 27 00:56:04 2022 -0500 Code refactor
130 lines
No EOL
4.3 KiB
C#
130 lines
No EOL
4.3 KiB
C#
using UnityEditor;
|
|
using UnityEngine;
|
|
|
|
namespace AndroidUltimatePlugin.Helpers.Editor
|
|
{
|
|
public class FindMissingScriptsRecursively : EditorWindow
|
|
{
|
|
static int _goCount = 0, _componentsCount = 0, _missingCount = 0;
|
|
|
|
[MenuItem("Window/FindMissingScriptsRecursively")]
|
|
public static void ShowWindow()
|
|
{
|
|
GetWindow(typeof(FindMissingScriptsRecursively));
|
|
}
|
|
|
|
public void OnGUI()
|
|
{
|
|
if (GUILayout.Button("Find Missing Scripts in selected GameObjects"))
|
|
{
|
|
FindInSelected();
|
|
}
|
|
|
|
if (GUILayout.Button("Find Missing Scripts"))
|
|
{
|
|
FindAll();
|
|
}
|
|
EditorGUILayout.BeginHorizontal();
|
|
{
|
|
EditorGUILayout.LabelField("Component Scanned:");
|
|
EditorGUILayout.LabelField("" + (_componentsCount == -1 ? "---" : _componentsCount.ToString()));
|
|
}
|
|
EditorGUILayout.EndHorizontal();
|
|
|
|
EditorGUILayout.BeginHorizontal();
|
|
{
|
|
EditorGUILayout.LabelField("Object Scanned:");
|
|
EditorGUILayout.LabelField("" + (_goCount == -1 ? "---" : _goCount.ToString()));
|
|
}
|
|
EditorGUILayout.EndHorizontal();
|
|
|
|
EditorGUILayout.BeginHorizontal();
|
|
{
|
|
EditorGUILayout.LabelField("Possible Missing Scripts:");
|
|
EditorGUILayout.LabelField("" + (_missingCount == -1 ? "---" : _missingCount.ToString()));
|
|
}
|
|
EditorGUILayout.EndHorizontal();
|
|
}
|
|
|
|
private static void FindAll()
|
|
{
|
|
_componentsCount = 0;
|
|
_goCount = 0;
|
|
_missingCount = 0;
|
|
|
|
string[] assetsPaths = AssetDatabase.GetAllAssetPaths();
|
|
|
|
foreach (string assetPath in assetsPaths)
|
|
{
|
|
Object[] data = LoadAllAssetsAtPath(assetPath);
|
|
foreach (Object o in data)
|
|
{
|
|
if (o != null)
|
|
{
|
|
if (o is GameObject)
|
|
{
|
|
FindInGO((GameObject) o);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
Debug.Log($"Searched {_goCount} GameObjects, {_componentsCount} components, found {_missingCount} missing");
|
|
}
|
|
|
|
public static Object[] LoadAllAssetsAtPath(string assetPath)
|
|
{
|
|
return typeof(SceneAsset).Equals(AssetDatabase.GetMainAssetTypeAtPath(assetPath))
|
|
?
|
|
// prevent error "Do not use readobjectthreaded on scene objects!"
|
|
new[] {AssetDatabase.LoadMainAssetAtPath(assetPath)}
|
|
: AssetDatabase.LoadAllAssetsAtPath(assetPath);
|
|
}
|
|
|
|
private static void FindInSelected()
|
|
{
|
|
GameObject[] go = Selection.gameObjects;
|
|
_goCount = 0;
|
|
_componentsCount = 0;
|
|
_missingCount = 0;
|
|
foreach (GameObject g in go)
|
|
{
|
|
|
|
FindInGO(g);
|
|
}
|
|
|
|
Debug.Log($"Searched {_goCount} GameObjects, {_componentsCount} components, found {_missingCount} missing");
|
|
}
|
|
|
|
private static void FindInGO(GameObject g)
|
|
{
|
|
_goCount++;
|
|
Component[] components = g.GetComponents<Component>();
|
|
for (int i = 0; i < components.Length; i++)
|
|
{
|
|
_componentsCount++;
|
|
if (components[i] == null)
|
|
{
|
|
_missingCount++;
|
|
string s = g.name;
|
|
Transform t = g.transform;
|
|
while (t.parent != null)
|
|
{
|
|
var parent = t.parent;
|
|
s = parent.name + "/" + s;
|
|
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);
|
|
}
|
|
}
|
|
}
|
|
} |