본문 바로가기
개발/Unity

Unity)하이어라키 커스텀(Hierarchy Custom)

by 테샤르 2022. 8. 1.

하이어라키 커스텀(Hierarchy Custom)

 

여러 사람이 작업하다보면 Hierarchy의 Name으로는 구분이 힘들 경우가 종종 생긴다.

Nested Prefabs과 RunTime 과정에서 Instantiate Prefab 등등,

로직에 의해서 변경되는 Hierarchy등등 여러가지 경우로 인해서 점점 복잡해진다.

어떤 GameObject가 무엇을 포함하고있는지 구분하기 위해서 방법을 찾다가 

Hierarchy Custom을 하는 것을 알게되어서 이것저것 적용해보았다.

 

반응형

<CustomHierarchy>

using UnityEditor;
using UnityEngine;
using System.Collections.Generic;
/// <summary>
///  Custom Hierarchy - 프로젝트 및 RunTime 상황에서 변동을 확인하기 위해서 커스텀
/// </summary>
[InitializeOnLoad]

public class CustomHierarchy : MonoBehaviour
{
    static CustomHierarchy()
    {
        EditorApplication.hierarchyWindowItemOnGUI -= HandleHierarchyWindowItemOnGUI;
        EditorApplication.hierarchyWindowItemOnGUI += HandleHierarchyWindowItemOnGUI;
    }

    // 아이콘 참고 링크 : https://github.com/halak/unity-editor-icons
    /// <summary>
    /// Hierachy GUI
    /// </summary>
    /// <param name="instanceID"></param>
    /// <param name="selectionRect"></param>
    private static void HandleHierarchyWindowItemOnGUI(int instanceID, Rect selectionRect)
    {
        var obj = EditorUtility.InstanceIDToObject(instanceID);
        if (obj != null)
        {
            string componentName = string.Empty;

            var gameObject = obj as GameObject;
            bool activeFlag = false;

            List<Texture> iconTexture = new List<Texture>();



            //Animator
            if (gameObject.GetComponent<Animator>())
            {
                activeFlag = true;
                iconTexture.Add(EditorGUIUtility.IconContent("UnityEditor.Graphs.AnimatorControllerTool@2x").image);
            }

            //Animation Icon
            if (gameObject.GetComponent<Animation>())
            {
                activeFlag = true;
                iconTexture.Add(EditorGUIUtility.IconContent("Animation Icon").image);
            }


            if (activeFlag)
            {
                if (iconTexture.Count == 0)
                    iconTexture.Add(PrefabUtility.GetIconForGameObject(gameObject));    

                //-- 아이콘 16 x 16 
                float iconWidth = 16;
                int temp_iconsDrawedCount = iconTexture.Count;
                float lockAndMoreGap = (iconWidth * temp_iconsDrawedCount) - 2;
                for (int i =0;i< temp_iconsDrawedCount;i++)
                    GUI.DrawTexture(new Rect(selectionRect.xMax - lockAndMoreGap + (iconWidth * i), selectionRect.yMin, 16, 16), iconTexture[i]);
            }


        }
    }
}

 

 

https://diegogiacomelli.com.br/unitytips-changing-the-style-of-the-hierarchy-window-group-header/

 

unitytips: Changing the style of the Hierarchy Window Group Header

In my last #unitytips I demonstrated how you could create a visual header to any group of components on your hierarchy window using EditorApplication.hierarchyWindowItemOnGUI. Now I’m improving it allowing you to customize its style.

diegogiacomelli.com.br

 

 

https://github.com/febucci/unitypackage-custom-hierarchy/tree/093baf4e09c2cd21c284303a977ec112a43041a7

 

GitHub - febucci/unitypackage-custom-hierarchy: Unity package to help having a clearer Hierarchy view, organizing everything in

Unity package to help having a clearer Hierarchy view, organizing everything in a “tree view” and including extra informations like Components Icons and groups/divisors. - GitHub - febucci/unitypac...

github.com

 

https://yarnthen.github.io/yarnthencohosking/how%20to/2018/04/25/Unity-Custom-Hierarchy.html

 

How to create a custom Hierarchy for your Unity 3D with an editor

How to create a custom Hierarchy for your Unity 3D with an editor

yarnthen.github.io

 

★☆☆☆☆

 

반응형

댓글