Unity
[Unity] Custom Editor ( 커스텀 에디터 )
EveryDay.DevUp
2020. 4. 30. 17:39
유니티를 사용하다보면, 익스펙터 창에 추가로 보여주고 싶은 UI가 생길 수 있게 됨
예시 ) Camera2D 스크립트에서 Unity 실행 중에는 변화된 카메라의 사이즈를 보여주고 싶은 경우
실행 전에는 보이지 않던 Cam Size가 실행 후에 보이는 것을 확인 할 수 있음
using UnityEditor;
using UnityEngine;
[CustomEditor( typeof( Camera2D ) )]
public class Camera2DEditor : Editor
{
Camera2D _cam2D;
Vector2 _camSize = Vector2.zero;
private void OnEnable()
{
_cam2D = (Camera2D)target;
}
public override void OnInspectorGUI()
{
base.OnInspectorGUI();
_cam2D.minWidth = EditorGUILayout.IntField( "min width", _cam2D.minWidth );
_cam2D.minHeight = EditorGUILayout.IntField( "min height", _cam2D.minHeight );
_cam2D.matchWidth = EditorGUILayout.Toggle( "match width", _cam2D.matchWidth );
if( Application.isPlaying )
{
EditorGUILayout.IntField( "screen width", _cam2D.screenWidth );
EditorGUILayout.IntField( "screen height", _cam2D.screenHeight );
}
}
}
▶ UnityEditor를 상속받는 클래스를 생성
▶ 클래스 상단에 [ CustomEditor( typeof( 만들고자 하는 컴포넌트 ))]
▶ OnInspectorGUI에서 보여줄 내용 추가
▶ Unity 기본적으로 다양한 UI를 제공하고 있으며, 디테일하게도 수정이 가능함
세부적인 내용은 유니티 메뉴얼 사이트에서 확인할 수 있음
https://docs.unity3d.com/kr/2018.4/Manual/editor-CustomEditors.html
커스텀 에디터 - Unity 매뉴얼
게임 제작 속도를 높이는 비결은 많이 사용되는 컴포넌트에 대해 커스텀 에디터를 만드는 것입니다. 여기서는 오브젝트가 항상 한 포인트를 바라보도록 하는 매우 간단한 스크립트를 예로 들어
docs.unity3d.com