애플리케이션에 커스텀 창을 얼마든지 생성할 수 있습니다. 커스텀 창은 인스펙터, 씬 또는 기타 빌트인 창처럼 작동합니다. 이 방법은 게임의 하위시스템에 사용자 인터페이스를 추가하는 데 유용합니다.
아래의 간단한 절차를 따라 커스텀 에디터 창을 만들 수 있습니다.
커스텀 에디터 창을 만들기 위해서는 스크립트를 “Editor”라는 폴더 안에 저장해야 합니다. 에디터 창에서 파생되는 이 스크립트에 클래스를 만든 다음, 내부 OnGUI 함수에 GUI 컨트롤을 작성합니다.
using UnityEngine;
using UnityEditor;
using System.Collections;
public class Example : EditorWindow
{
void OnGUI () {
// The actual window code goes here
}
}
_ 프로젝트 내 ‘Editor’ 폴더에 있는 MyWindow.js_
화면에 창을 표시하려면 창을 표시하는 메뉴 아이템을 생성합니다. 이 작업은 MenuItem 프로퍼티를 통해 활성화되는 함수를 작성하여 수행합니다.
Unity의 기본 설정은 창을 재활용합니다 따라서 메뉴 아이템을 다시 선택하면 기존 창이 표시됩니다. 이 작업은 EditorWindow.GetWindow 함수를 사용하여 수행됩니다. 예제:
using UnityEngine;
using UnityEditor;
using System.Collections;
class MyWindow : EditorWindow {
[MenuItem ("Window/My Window")]
public static void ShowWindow () {
EditorWindow.GetWindow(typeof(MyWindow));
}
void OnGUI () {
// The actual window code goes here
}
}
MyWindow 표시
호출 간 포지션을 저장하거나 커스텀 레이아웃에 사용하는 등 도킹 가능한 스탠다드 에디터 창을 생성할 수 있습니다. 생성한 창에 더 많은 컨트롤을 적용하려면 GetWindowWithRect를 사용할 수 있습니다.
창의 실제 콘텐츠는 OnGUI 함수를 구현하여 렌더링합니다. 인게임 GUI(GUI 및 GUILayout)에 사용하는 것과 동일한 UnityGUI 클래스를 사용할 수 있습니다. 또한 EditorGUI 및 EditorGUILayout 에디터 전용 클래스에 있는 GUI 컨트롤도 몇 개 더 제공됩니다. 이 클래스는 일반 클래스에 이미 사용 가능한 컨트롤에 추가되므로 원하는 경우 믹스 앤 매치를 할 수 있습니다.
다음 C# 코드는 커스텀 에디터 창에 GUI 요소를 추가하는 방법을 나타냅니다.
using UnityEditor;
using UnityEngine;
public class MyWindow : EditorWindow
{
string myString = "Hello World";
bool groupEnabled;
bool myBool = true;
float myFloat = 1.23f;
// Add menu item named "My Window" to the Window menu
[MenuItem("Window/My Window")]
public static void ShowWindow()
{
//Show existing window instance. If one doesn't exist, make one.
EditorWindow.GetWindow(typeof(MyWindow));
}
void OnGUI()
{
GUILayout.Label ("Base Settings", EditorStyles.boldLabel);
myString = EditorGUILayout.TextField ("Text Field", myString);
groupEnabled = EditorGUILayout.BeginToggleGroup ("Optional Settings", groupEnabled);
myBool = EditorGUILayout.Toggle ("Toggle", myBool);
myFloat = EditorGUILayout.Slider ("Slider", myFloat, -3, 3);
EditorGUILayout.EndToggleGroup ();
}
}
위의 예제를 통해 생성된 창은 다음과 같습니다.
자세한 내용은 에디터 창 페이지의 예제와 문서를 참조하십시오.
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.