Posts 유니티 에디터 - Built-in Icons
Post
Cancel

유니티 에디터 - Built-in Icons

Note


  • 유니티 에디터에 내장된 아이콘들이 존재한다.

  • UnityEditor.EditorGUIUtility.IconContent("이름")을 통해 GUIContent 타입으로 로드할 수 있다.

  • UnityEditor.EditorGUIUtility.FindTexture("이름")을 통해 Texture2D 타입으로 로드할 수 있다.


아이콘 목록 확인



사용 예시


[1] IconContent

2021_0829_EditorButton1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[CustomEditor(typeof(TestTest))]
private class CE : UnityEditor.Editor
{
    private static GUIContent playIconContent;

    private void OnEnable()
    {
        if (playIconContent == null)
            playIconContent = EditorGUIUtility.IconContent("PlayButton@2x");
    }

    public override void OnInspectorGUI()
    {
        GUILayout.Button(playIconContent, GUILayout.Width(40f), GUILayout.Height(40f));
    }
}


[2] FindTexture

2021_0829_EditorButton2

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
[CustomEditor(typeof(TestTest))]
private class CE : UnityEditor.Editor
{
    private static Texture2D playIconTex;
    private static Texture2D playOnIconTex;
    private static GUIStyle buttonStyle;

    private void OnEnable()
    {
        if (playIconTex == null)
            playIconTex = EditorGUIUtility.FindTexture("PlayButton@2x");
        if (playOnIconTex == null)
            playOnIconTex = EditorGUIUtility.FindTexture("PlayButton On@2x");
    }

    public override void OnInspectorGUI()
    {
        if (buttonStyle == null) // 스타일은 반드시 OnInspectorGUI()에서 참조
            buttonStyle = "button";

        var oldNormalTex = buttonStyle.normal.background;
        var oldActiveTex = buttonStyle.active.background;

        if(playIconTex != null)   buttonStyle.normal.background = playIconTex;
        if(playOnIconTex != null) buttonStyle.active.background = playOnIconTex;

        GUILayout.Button(" ", GUILayout.Width(40f), GUILayout.Height(40f));

        buttonStyle.normal.background = oldNormalTex;
        buttonStyle.active.background = oldActiveTex;
    }
}
This post is licensed under CC BY 4.0 by the author.