๐ŸŽฎ Unity Study/Unity

[Unity] Editor Programming

ibelieveinme 2023. 3. 28. 13:55
728x90

ํ…์ŠคํŠธ์˜ ํฐํŠธ๋ฅผ ์ผ๊ด„์ ์œผ๋กœ ๋ฐ”๊ฟ”์•ผ ํ•  ๋•Œ, ํŠน์ • ๊ฐ์ฒด๋ฅผ ๋ชจ๋‘ ์ง€์›Œ์•ผํ•  ๋•Œ ๋“ฑ๋“ฑ ๋ฌด์˜๋ฏธํ•œ ๋ฐ˜๋ณต์ž‘์—…์„ ์ˆ˜ํ–‰ํ•ด์•ผ ํ•˜๋Š” ๊ฒฝ์šฐ๊ฐ€ ์žˆ๋‹ค.

์ด๋Ÿด ๋•Œ Editor Programming์„ ์‚ฌ์šฉํ•œ๋‹ค๋ฉด ๋น ๋ฅด๊ณ  ์‰ฝ๊ณ  ์ •ํ™•ํ•˜๊ฒŒ ๋ณ€๊ฒฝ์ด ๊ฐ€๋Šฅํ•˜๋‹ค.

๋” ํšจ์œจ์ ์ธ ๊ฐœ๋ฐœ์„ ์œ„ํ•ด์„œ๋Š” ํ•„์ˆ˜๋‹ค !

 

 

1. ์ƒ๋‹จ ๋ฉ”๋‰ด ์ƒ์„ฑํ•˜๊ณ  ๋นˆ Editor ํ™”๋ฉด ๋งŒ๋“ค๊ธฐ 

using UnityEditor;

public class MyEditorWindow : EditorWindow
{
    [MenuItem("MyTool/Open MyTool %g")]
    static void Open() {
        var window = GetWindow<MyEditorWindow>();
        window.title = "MyTool";
    }
}

์ƒ๋‹จ์— MyTool ๋ฉ”๋‰ด๋ฅผ ๋งŒ๋“ค๊ณ  ๋ฉ”๋‰ด๋ฅผ ์—ด๋ฉด Open MyTool ๋ฉ”๋‰ด๊ฐ€ ์ƒ์„ฑ๋œ๋‹ค.

๋‹จ์ถ•ํ‚ค Command + g ๋กœ ์—ด์ˆ˜๋„ ์žˆ๋‹ค.

ํ•ด๋‹น ๋ฒ„ํŠผ์„ ๋ˆ„๋ฅด๋ฉด  Open ํ•จ์ˆ˜๊ฐ€ ์‹คํ–‰๋˜๋ฉฐ Editor Window๋ฅผ ์—ฐ๋‹ค.

Editor Window ์˜ ํƒ€์ดํ‹€์€ MyTool์ด๋‹ค.

 

2. GUI(๋ผ๋ฒจ, ํ…์ŠคํŠธ, ๋ฒ„ํŠผ) ๋งŒ๋“ค๊ธฐ

using UnityEngine;
using UnityEditor;


public class MyEditorWindow : EditorWindow
{
    [MenuItem("MyTool/Open MyTool %g")]
    static void Open() {
        var window = GetWindow<MyEditorWindow>();
        window.title = "MyTool";
    }

    private void OnGUI() {
        EditorGUILayout.LabelField("Label!");
        EditorGUILayout.TextField("Text!");
        GUILayout.Button("Button");
    }
}

์ฃผ์˜) EditorGUI ์ฝ”๋“œ๋Š” ์˜ˆ์•ฝ๋œ ํ•จ์ˆ˜(OnGUI)์—์„œ๋งŒ ์‚ฌ์šฉํ•ด์•ผ ํ•œ๋‹ค.

GUI์™€ EditorGUI์˜ ์ฐจ์ด ?

GUI / GUILayout: Editor / ๋Ÿฐํƒ€์ž„์šฉ

EditorGUI / EditorGUILayout: Only Editor

 

 

3. ๋‹ค์–‘ํ•œ GUI ๋งŒ๋“ค๊ธฐ

using UnityEngine;
using UnityEditor;


public class MyEditorWindow : EditorWindow
{
    int intValue;
    float floatValue;
    Color colorValue;
    Gradient gradientValue = new Gradient();
    Vector3 vector3Value;
    Vector3Int vector3IntValue;
    Rect rectValue;
    Object objectValue;
    string passwordValue;
    string tagValue;
    ParticleSystemCollisionType enumValue;
    bool toggleValue;
    string[] stringArr = new string[] { "String01", "String02", "String03", "String04", "String05", "String06" };
    int selectionValue;


    [MenuItem("MyTool/Open MyTool %g")]
    static void Open() {
        var window = GetWindow<MyEditorWindow>();
        window.title = "MyTool";
    }

    private void OnGUI() {

        #region EditorGUILayout

        intValue = EditorGUILayout.IntField("Int๊ฐ’", intValue);
        floatValue = EditorGUILayout.FloatField("Float๊ฐ’", floatValue);
        colorValue = EditorGUILayout.ColorField("Color๊ฐ’", colorValue);
        gradientValue = EditorGUILayout.GradientField("Gradient๊ฐ’", gradientValue);
        vector3Value = EditorGUILayout.Vector3Field("Vector3๊ฐ’", vector3Value);
        vector3IntValue = EditorGUILayout.Vector3IntField("Vector3Int๊ฐ’", vector3IntValue);
        rectValue = EditorGUILayout.RectField("Rect๊ฐ’", rectValue);
        objectValue = EditorGUILayout.ObjectField("Object๊ฐ’", objectValue, typeof(Object), false);
        passwordValue = EditorGUILayout.PasswordField("Password๊ฐ’", passwordValue);
        tagValue = EditorGUILayout.TagField("tag๊ฐ’", tagValue);
        enumValue = (ParticleSystemCollisionType)EditorGUILayout.EnumFlagsField("Enum๊ฐ’", enumValue);
        floatValue = EditorGUILayout.Slider("Slider๊ฐ’", floatValue, 0, 100);
        EditorGUILayout.HelpBox("Help Box", MessageType.Error);
        toggleValue = EditorGUILayout.Toggle("Toggle๊ฐ’", toggleValue);

        //์ค„ ๊ธ‹๊ธฐ
        EditorGUILayout.LabelField("", GUI.skin.horizontalSlider);

        #endregion



        #region GUILayout

        selectionValue = GUILayout.Toolbar(selectionValue, stringArr);
        GUILayout.Space(15);
        selectionValue = GUILayout.SelectionGrid(selectionValue, stringArr, 2);
        GUILayout.Box(EditorGUIUtility.IconContent("Animation.Record"));

        #endregion
    }
}

 

๋งจ ๋งˆ์ง€๋ง‰์€ ์•„์ด์ฝ˜๋ชจ์–‘์„ ๋…ธ์ถœ์‹œํ‚ค๋Š”๊ฑด๋ฐ, ์•„๋ž˜ ์‚ฌ์ดํŠธ์— ๊ฐ€๋ฉด ๋‹ค์–‘ํ•œ ๋ชจ์–‘์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.

https://github.com/halak/unity-editor-icons

 

GitHub - halak/unity-editor-icons

Contribute to halak/unity-editor-icons development by creating an account on GitHub.

github.com

 

Unity ๊ณต์‹ ๋ฌธ์„œ ์ฐธ๊ณ 

https://docs.unity3d.com/ScriptReference/EditorGUILayout.html

 

Unity - Scripting API: EditorGUILayout

Success! Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable. Close

docs.unity3d.com

 

728x90