Posts 유니티 - Custom Editor Window(커스텀 에디터 윈도우)
Post
Cancel

유니티 - Custom Editor Window(커스텀 에디터 윈도우)

Note


  • 에디터 윈도우를 직접 만들어 사용할 수 있다.

Preview


image


Source Code Example


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#if UNITY_EDITOR

using UnityEngine;
using UnityEditor;

public class ExampleWindow : EditorWindow
{
    private bool boolValue;
    private float floatValue;
    private Vector3 vector3Value;

    [MenuItem("Window/Rito/Example Window")] // 메뉴 등록
    private static void Init()
    {
        // 현재 활성화된 윈도우 가져오며, 없으면 새로 생성
        ExampleWindow window = (ExampleWindow)GetWindow(typeof(ExampleWindow));
        window.Show();

        // 윈도우 타이틀 지정
        window.titleContent.text = "W I N D O W";

        // 최소, 최대 크기 지정
        window.minSize = new Vector2(340f, 150f);
        window.maxSize = new Vector2(340f, 200f);
    }

    void OnGUI()
    {
        // 굵은 글씨 
        Color originColor = EditorStyles.boldLabel.normal.textColor;
        EditorStyles.boldLabel.normal.textColor = Color.yellow;

        // Header =====================================================================
        GUILayout.Space(10f);
        GUILayout.Label("Header Label", EditorStyles.boldLabel);

        vector3Value = EditorGUILayout.Vector3Field("Vector3", vector3Value);

        // ============================================================================
        GUILayout.Space(10f);
        GUILayout.Label("Horizontal", EditorStyles.boldLabel);

        // Horizontal =================================================================
        GUILayout.BeginVertical();

        boolValue = EditorGUILayout.Toggle("Bool", boolValue);
        floatValue = EditorGUILayout.FloatField("Float", floatValue);

        GUILayout.EndVertical();

        // Horizontal =================================================================
        GUILayout.BeginHorizontal();

        GUILayout.Label("Label Left");
        GUILayout.Label("Label Right");

        GUILayout.EndHorizontal();
        // ============================================================================

        EditorStyles.boldLabel.normal.textColor = originColor;
    }
}

#endif
This post is licensed under CC BY 4.0 by the author.