Last active
August 29, 2015 14:23
-
-
Save fuqunaga/84fe5634cdcb01de8619 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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