유니티 스크립트 Missing 한번에 지우기 (SelectGameObjectsWithMissingScripts)

Unity3D 2022. 5. 10. 12:04
반응형
using UnityEngine;
using UnityEditor;
using System.Collections.Generic;
using UnityEngine.SceneManagement; //3

public class SelectGameObjectsWithMissingScripts : Editor
{
    [MenuItem("smilejsu/Remove All Missing Script Components")]
    private static void RemoveAllMissingScriptComponents() {

        Object[] deepSelectedObjects = EditorUtility.CollectDeepHierarchy(Selection.gameObjects);

        Debug.Log(deepSelectedObjects.Length);

        int componentCount = 0;
        int gameObjectCount = 0;

        foreach (Object obj in deepSelectedObjects)
        {
            if (obj is GameObject go)
            {
                int count = GameObjectUtility.GetMonoBehavioursWithMissingScriptCount(go);

                //Debug.LogFormat("<color=cyan>{0}</color>", count);

                if (count > 0) {
                    Undo.RegisterCompleteObjectUndo(go, "Remove Missing Scripts");

                    GameObjectUtility.RemoveMonoBehavioursWithMissingScript(go);

                    componentCount += count;
                    gameObjectCount++;
                }

            }
        }

    }
}

 

 

게임 오브젝트를 선택하고 메뉴에서 Remove를 눌러주면 

자식 오브젝트들을 모두 검색해 Missiing 난 스크립트 컴포넌트를 제거 합니다 

반응형
: