flattens the hierarchy by assigning all child objects directly to an parent in the Unity Editor. 모든 자식을 하나의 부모로 평탄화 하는 스크립트

2024. 4. 30. 16:07· 카테고리 없음
728x90
 
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
public class HierarchyFlattor: EditorWindow
{
    private Transform _parent;

    [MenuItem("Tools/HierarchyFlattor")]


    public static void ShowWindow()
    {
        GetWindow<HierarchyFlattor>("HierarchyFlattor");
    }


    private void OnGUI()
    {
        GUILayout.Label("Set all childs parent to selected parent", EditorStyles.boldLabel);
        _parent = EditorGUILayout.ObjectField("Parent Object", _parent, typeof(Transform), true) as Transform;

        if(GUILayout.Button("Flatten"))
        {
            if(_parent != null)
            {
                Execute(_parent);
            }
        }

    }

    public void Execute(Transform parent)
    {
        List<Transform> allChild = new();
        AddAllChild(allChild, _parent);


        FlattenAllSub(allChild, parent);
    }

    private void AddAllChild(List<Transform> container, Transform parant)
    {
        for (int i = 0; i < parant.childCount; i++)
        {
            Transform CurChild = parant.GetChild(i).transform;
            container.Add(CurChild);
            AddAllChild(container, CurChild);
        }
    }
    private void FlattenAllSub(List<Transform> container, Transform parent)
    {
        foreach (Transform child in container)
        {
            Debug.Log($"Flatten{child.name}");
            Undo.SetTransformParent(child, parent, "Flatten All Sub");
        }
    }



}

Asset에 Editor 폴더 생성후 스크립트를 그 안에 넣은후 Tool에서 HierarchyFlattor 실행하면 됩니다.

 

실행전

 

실행위치

 

실행창

 

결과

 
728x90
시코.
시코.
250x250
시코.
시코
시코.
전체
오늘
어제
  • 분류 전체보기 (45)
    • 블렌더 (1)
    • C# (5)
    • c++ 잊었던것, 사소한것 (4)
    • c++ (4)
      • 백준 (2)
    • 어소트락 무료강의 (2)
      • c++win32api (2)
    • 수학 (2)
      • 3d기초 (1)
    • 알고리즘 (2)
    • 타자연습 (0)
    • 영어 (0)
    • 물리엔진 (0)
    • 구글 코딩스타일 (0)

블로그 메뉴

  • 홈
  • 태그
  • 방명록

공지사항

인기 글

태그

  • geometry node
  • 파이썬
  • extern "C"
  • 속성
  • 깃허브
  • attribute
  • 지오메트리노드
  • 어소트락 무료강의
  • Diagram
  • 3D
  • CLASS
  • 블렌더
  • blender
  • UML

최근 댓글

최근 글

hELLO · Designed By 정상우.v4.2.2
시코.
flattens the hierarchy by assigning all child objects directly to an parent in the Unity Editor. 모든 자식을 하나의 부모로 평탄화 하는 스크립트
상단으로

티스토리툴바

단축키

내 블로그

내 블로그 - 관리자 홈 전환
Q
Q
새 글 쓰기
W
W

블로그 게시글

글 수정 (권한 있는 경우)
E
E
댓글 영역으로 이동
C
C

모든 영역

이 페이지의 URL 복사
S
S
맨 위로 이동
T
T
티스토리 홈 이동
H
H
단축키 안내
Shift + /
⇧ + /

* 단축키는 한글/영문 대소문자로 이용 가능하며, 티스토리 기본 도메인에서만 동작합니다.