Skip to content

Instantly share code, notes, and snippets.

@baba-s
Created December 8, 2013 11:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save baba-s/7855986 to your computer and use it in GitHub Desktop.
Save baba-s/7855986 to your computer and use it in GitHub Desktop.
using System.Linq;
using UnityEditor;
using UnityEngine;
/// <summary>
/// Missing Scriptsを抽出するスクリプト
/// </summary>
[InitializeOnLoad]
internal class MissingScriptChecker : Editor
{
/// <summary>
/// エディタ起動時にMissing Scriptsを抽出する
/// </summary>
static MissingScriptChecker()
{
if (EditorApplication.isPlaying || Application.isPlaying)
{
return;
}
Check();
}
/// <summary>
/// メニューからMissing Scriptsを抽出する
/// </summary>
[MenuItem("Tools/Check/Missing Script")]
private static void CheckMissingScript()
{
Check();
}
/// <summary>
/// Missing Scriptsを抽出する
/// </summary>
private static void Check()
{
Debug.Log("Start Missing Script Checker");
// 1. 全てのゲームオブジェクトを見つけます
// 2. 各々のオブジェクトをチェックします
// 3. 全てのコンポーネントを取得します
// 4. null を戻すものがあるか確認します
var brokenList =
Resources.FindObjectsOfTypeAll(typeof(GameObject)).Cast<GameObject>().Where(
c => c.GetComponents<MonoBehaviour>().Any(o => o == null)).ToList();
foreach (var broken in brokenList)
{
Debug.LogError(broken.name, broken);
}
Debug.Log("Complete Missing Script Checker");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment