GameObject의 Missing Script 삭제 자동화

2023. 5. 17. 15:27·Unity/Tip
반응형

다음은 누락된 스크립트를 자동으로 제거하는 코드입니다. 이 코드를 사용하면 선택한 게임 오브젝트에서 누락된 스크립트를 모두 제거할 수 있습니다.

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에서 유용한 클래스 이름  (1) 2023.05.13
Unity의 컨디셔널 컴플리션(Conditional Compilation)  (0) 2023.05.10
Unity Debuging  (0) 2023.05.09
'Unity/Tip' 카테고리의 다른 글
  • Binary Space Partitioning (BSP)란?
  • Unity 최적화 기법
  • Unity에서 유용한 클래스 이름
  • Unity의 컨디셔널 컴플리션(Conditional Compilation)
코샵
코샵
나의 코딩 일기장
    반응형
  • 코샵
    끄적끄적 코딩 공방
    코샵
    • 분류 전체보기 (658)
      • 상품 추천 (164)
      • MongoDB (4)
      • 하드웨어 (11)
      • 일기장 (4)
      • Unity (138)
        • Tip (41)
        • Project (1)
        • Design Pattern (8)
        • Firebase (6)
        • Asset (2)
      • 파이썬 (12)
        • Basic (41)
        • OpenCV (8)
        • Pandas (15)
        • PyQT (3)
        • SBC(Single Board Computer) (1)
        • 크롤링 (14)
        • Fast API (29)
        • Package (6)
      • Linux (4)
      • C# (97)
        • Algorithm (11)
        • Window (7)
      • TypeScript (50)
        • CSS (10)
      • Git (11)
      • SQL (5)
      • Flutter (10)
        • Tip (1)
      • System (1)
      • BaekJoon (6)
      • Portfolio (2)
      • MacOS (1)
      • 유틸리티 (1)
      • 서비스 (6)
      • 자동화 (3)
      • Hobby (10)
        • 물생활 (10)
        • 식집사 (0)
  • 인기 글

  • 태그

    리뷰이관
    리뷰관리
    스크립트 실행
    리스트
    unity
    list
    스마트스토어리뷰
    codingtips
    카페24리뷰이관
    셀레니움
    스크립트 실행 순서
    라떼우유
    ipcamera
    긴유통기한우유
    쇼핑몰리뷰
    유니티
    appdevelopment
    learntocode
    카페24리뷰
    cv2
    상품 리뷰 크롤링
    C#
    Python
    믈레코비타멸균우유
    programmerlife
    devlife
    programming101
    rtsp
    codingcommunity
    파이썬
  • 최근 글

  • hELLO· Designed By정상우.v4.10.3
코샵
GameObject의 Missing Script 삭제 자동화
상단으로

티스토리툴바