Skip to content

Instantly share code, notes, and snippets.

@fuqunaga
Last active August 29, 2015 14:23
Show Gist options
  • Save fuqunaga/84fe5634cdcb01de8619 to your computer and use it in GitHub Desktop.
Save fuqunaga/84fe5634cdcb01de8619 to your computer and use it in GitHub Desktop.
using UnityEditor;
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
[InitializeOnLoad]
class MissingScriptChecker : Editor
{
[MenuItem("GameObject/Missing Script Checker")]
static void MissingScriptCheckerFunction()
{
StartCheck();
}
static MissingScriptChecker()
{
if (EditorApplication.isPlaying || Application.isPlaying)
return;
StartCheck();
}
static void StartCheck()
{
Debug.Log("Run MissingScriptChecker");
List<GameObject> brokenList =
// 全てのゲームオブジェクトを見つける
Resources.FindObjectsOfTypeAll(typeof(GameObject))
.Cast <GameObject>()
// 各々のオブジェクトをチェック
.Where(
// 全てのコンポーネントを取得
c => c.GetComponents<Component>()
// null を戻すものごあるか確認
.Any(o => o == null)
)
.ToList();
foreach (GameObject gobj in brokenList)
Debug.LogError(gobj.name, gobj);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment