您最多选择25个主题 主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

50 行
1.8 KiB

using UnityEngine;
using UnityEditor;
/// <summary>
/// Small editor utility to help with finding stripped scripts.
/// This is useful when excluding assemblies from a build for example.
/// </summary>
public class FindMissingScripts : EditorWindow
{
[MenuItem("Window/FindMissingScripts")]
public static void ShowWindow()
{
FindInSelected();
}
static void FindInSelected()
{
GameObject[] allObjects = FindObjectsOfType<GameObject>();
string result = "";
int gameObjectsCount = 0, componentsCount = 0, missingCount = 0;
foreach (GameObject gameObject in allObjects)
{
gameObjectsCount++;
var components = gameObject.GetComponentsInChildren<MonoBehaviour>();
for (int i = 0; i < components.Length; i++)
{
componentsCount++;
if (components[i] == null)
{
missingCount++;
string gameObjectName = gameObject.name;
Transform t = gameObject.transform;
while (t.parent != null)
{
gameObjectName = t.parent.name + "/" + gameObjectName;
t = t.parent;
}
var currentMessage = $"{gameObjectName} has an empty script attached in position: {i}\n";
Debug.Log(currentMessage, gameObject); // so we can click on the gameObject's context
result += currentMessage;
}
}
}
Debug.Log(result);
Debug.Log($"Searched {gameObjectsCount} GameObjects, {componentsCount} components, found {missingCount} missing");
}
}