유니티 엔진 (Unity Engine)

[Unity] Custom Editor, ReorderableList 적용하기

원소랑 2020. 10. 13. 02:56
728x90

.

유니티 에디터에서 Inspector 를 이쁘게 정리하기 위해 ReorderableList 적용하기 포스트.

사용해야할 기본 코드

using UnityEditorInternal;

// 클래스 내에서
private ReorderableList list;

private void OnEnable()
{
    list = new ReorderableList(serializedObject,
            serializedObject.FindProperty("TriggerList"),
            true, true, true, true);
    // Element 가 그려질 때 Callback
    list.drawElementCallback =
        (Rect rect, int index, bool isActive, bool isFocused) => {
            // 현재 그려질 요소
            SerializedProperty element = list.serializedProperty.GetArrayElementAtIndex(index);
            rect.y += 2; // 위쪽 패딩
            EditorGUI.PropertyField(
                new Rect(rect.x, rect.y, 100, EditorGUIUtility.singleLineHeight),
                element.FindPropertyRelative("eTriggerType"), GUIContent.none);
            EditorGUI.PropertyField(
                new Rect(rect.x + 100, rect.y, rect.width - 100 - 30, EditorGUIUtility.singleLineHeight),
                element.FindPropertyRelative("ConditoinList"), GUIContent.none);
        };
}
public override void OnInspectorGUI()
{
    serializedObject.Update();
    list.DoLayoutList();
    serializedObject.ApplyModifiedProperties();
}

위 코드처럼 구성하면 일단 아래처럼 기본 구성 띄우는 건 성공.

구체적인 커스터마이징은 좀 더 자료를 찾아보니 금방 나오는군요. 아래쪽에 참고 링크들 추가. 장기적으로 편리하게 사용하려면 GUI 도 잘 만들어둬야겠습니다.

https://m.blog.naver.com/hammerimpact/220775710045

 

[에디터 확장 입문] 번역 14장 ReorderbleList

http://anchan828.github.io/editor-manual/web/reorderblelist.html14장 ReorderbleListReorderbleLis...

blog.naver.com

unityindepth.tistory.com/56

 

ReorderableList으로 다양한 기능을 가진 List구현하기

원본보기 유니티 4.5버전에서, 유니티 인스펙터창에 비주얼한 리스트를 만들수 있는 내장 기능이 추가 되었다. 이 기능을 가진 클래스의 이름은 ReorderableList이며, UnityEditorInternal 네임스페이스��

unityindepth.tistory.com

https://stackoverflow.com/questions/54516221/how-to-select-elements-in-nested-reorderablelist-in-a-customeditor

 

How to select elements in nested ReorderableList in a CustomEditor?

I have a ReorderableList in my CustomEditor script. In the drawElementCallback I added a second nested ReorderableList. Everything works fine and I can add elements to both lists like here BUT as ...

stackoverflow.com

 

 

유니티 교과서 개정 5판 2021버전 게임 프로그래밍 제작 독학 책

COUPANG

www.coupang.com

728x90
반응형