Last active
November 29, 2016 11:11
-
-
Save fuqunaga/9ee907fccf921bfe907903d1617d96d6 to your computer and use it in GitHub Desktop.
EditorTestRunnerでMissingScriptをチェック
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 UnityEngine; | |
using UnityEditor; | |
using NUnit.Framework; | |
using System.Linq; | |
using UnityEditor.SceneManagement; | |
public class CommonTest | |
{ | |
/// <summary> | |
/// Sceneを開きそのときロードされているオブジェクトから参照破損をチェックする | |
/// "/scenePath Assets/Scenes/main.unity"のようにコマンドライン引き数で対象シーンを指定できる | |
/// 指定しない場合はすべてのシーンのチェックを行う | |
/// </summary> | |
[Test] | |
public void FindMissingScript() | |
{ | |
var setups = EditorSceneManager.GetSceneManagerSetup(); | |
var args = System.Environment.GetCommandLineArgs().ToList(); | |
var idx = args.IndexOf("/scenePath"); | |
var pathes = (idx >= 0) | |
? new[] { args[idx + 1] } | |
: AssetDatabase.FindAssets("t:scene").Select(guid => AssetDatabase.GUIDToAssetPath(guid)); | |
pathes.ToList().ForEach(path => | |
{ | |
var scene = EditorSceneManager.OpenScene(path); | |
var brokenList = Resources.FindObjectsOfTypeAll<GameObject>().Where(c => c.GetComponents<Component>().Any(o => o == null)); | |
if (brokenList.Any()) | |
{ | |
brokenList = brokenList.OrderBy(c => c.name).ToList(); | |
Selection.activeGameObject = brokenList.First(); | |
EditorGUIUtility.PingObject(Selection.activeGameObject); | |
Assert.IsTrue(false, "Scene:[" + scene.name + "] " + string.Join(",", brokenList.Select(c => c.name).ToArray())); | |
} | |
}); | |
if (setups.Any()) | |
{ | |
EditorSceneManager.OpenScene(setups.First().path, OpenSceneMode.Single); | |
setups.Skip(1).ToList().ForEach(setup => EditorSceneManager.OpenScene(setup.path, OpenSceneMode.Additive)); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment