반응형
다음은 누락된 스크립트를 자동으로 제거하는 코드입니다. 이 코드를 사용하면 선택한 게임 오브젝트에서 누락된 스크립트를 모두 제거할 수 있습니다.
using UnityEditor;
using UnityEngine;
public class SelectGameObjectsWithMissingScripts : Editor
{
[MenuItem("Utility/Remove Missing Script")]
private static void RemoveAllMissingScriptComponents()
{
var selectedGameObjects = Selection.gameObjects;
int totalComponentCount = 0;
int totalGameObjectCount = 0;
foreach (var gameObject in selectedGameObjects)
{
int missingScriptCount = GameObjectUtility.GetMonoBehavioursWithMissingScriptCount(gameObject);
if (missingScriptCount > 0)
{
Undo.RegisterCompleteObjectUndo(gameObject, "Remove Missing Scripts");
GameObjectUtility.RemoveMonoBehavioursWithMissingScript(gameObject);
totalComponentCount += missingScriptCount;
totalGameObjectCount++;
}
}
Debug.Log($"Removed {totalComponentCount} missing script component(s) from {totalGameObjectCount} game object(s).");
}
}
이 코드는 에디터에서 실행되는 코드이며, 에디터의 메뉴에서 "Utility/Remove Missing Script"를 선택하여 실행할 수 있습니다. 인스펙터 창에서 Missing Script를 제거할 대상의 게임 오브젝트를 선택하고 실행하시면 됩니다.
'Unity > Tip' 카테고리의 다른 글
Binary Space Partitioning (BSP)란? (0) | 2023.06.12 |
---|---|
Unity 최적화 기법 (0) | 2023.06.11 |
Unity에서 유용한 클래스 이름 (0) | 2023.05.13 |
Unity의 컨디셔널 컴플리션(Conditional Compilation) (0) | 2023.05.10 |
Unity Debuging (0) | 2023.05.09 |