탭형식 Window

static CustomEditor_Window Inst_Editor_Window = null;
    //! 일반적인 윈도우
    [MenuItem("CustomEditor/EditorWindow")]
    static void EditorWindow()
    {
        if (Inst_Editor_Window == null)
        {
            Inst_Editor_Window = GetWindow<CustomEditor_Window>(typeof(CustomEditor_Window));
        }
        Inst_Editor_Window.Show();
    }
    
    public class CustomEditor_Window : EditorWindow
{
    void OnGUI()
    {
        EditorGUILayout.LabelField("일반적인 윈도우");
    }
}

 

 

탭형식 Window - 특정 탭옆에 소환

//! 일반 윈도우를 특정 탭옆에 소환하기
    [MenuItem("CustomEditor/EditorWindow_AddToSceneView")]
    static void EditorWindow_AddToSceneView()
    {
        if (Inst_Editor_Window == null)
        {
            Inst_Editor_Window = GetWindow<CustomEditor_Window>(typeof(SceneView));
        }
        Inst_Editor_Window.Show();
    }
    
    public class CustomEditor_Window : EditorWindow
{
    void OnGUI()
    {
        EditorGUILayout.LabelField("일반적인 윈도우");
    }
}

 

 

AuxWindow - 일반 윈도우, 포커스가 다른 곳으로 변경되면 자동으로 종료됨

    static CustomEditor_AuxWindow Inst_Editor_AuxWindow = null;
    //! 일반 윈도우, 포커스가 다른곳으로 되면 자동으로 종료됨
    [MenuItem("CustomEditor/EditorWindow_AuxWindow")]
    static void EditorWindow_AuxWindow()
    {
        if (Inst_Editor_AuxWindow == null)
        {
            Inst_Editor_AuxWindow = CreateInstance<CustomEditor_AuxWindow>();
        }
        Inst_Editor_AuxWindow.ShowAuxWindow();
    }


public class CustomEditor_AuxWindow : EditorWindow
{
    void OnGUI()
    {
        EditorGUILayout.LabelField("일반 윈도우, 포커스가 다른곳으로 되면 자동으로 종료됨");
    }
}

 

Utility - 일반 윈도우와 동일하지만 항상 맨 앞에 보임

static CustomEditor_Utility Inst_Editor_Utility = null;
    //! 유틸리티 윈도우, 일반 윈도우와 동일하지만 항상 소팅이 맨앞에 보이게됨
    [MenuItem("CustomEditor/EditorWindow_Utility")]
    static void EditorWindow_Utility()
    {
        if (Inst_Editor_Utility == null)
        {
            Inst_Editor_Utility = CreateInstance<CustomEditor_Utility>();
        }
        Inst_Editor_Utility.ShowUtility();
    }

public class CustomEditor_Utility : EditorWindow
{
    void OnGUI()
    {
        EditorGUILayout.LabelField("유틸리티 윈도우, 일반 윈도우와 동일하지만 항상 소팅이 맨앞에 보이게됨");
    }
}

 

 

Popup - 상단바도 없는 제일 단순한 윈도우, 종료하고 싶으면 내부 스크립트로 호출해야함.

   static CustomEditor_Popup Inst_Editor_Popup = null;
    //! 상단바도 없는 제일 단순한 윈도우, 종료할때 내부 스크립트로 수동으로 꺼야함
    [MenuItem("CustomEditor/EditorWindow_Popup")]
    static void EditorWindow_Popup()
    {
        if (Inst_Editor_Popup == null)
        {
            Inst_Editor_Popup = CreateInstance<CustomEditor_Popup>();
        }
        Inst_Editor_Popup.ShowPopup();
    }
    
    
public class CustomEditor_Popup : EditorWindow
{
    void OnGUI()
    {
        EditorGUILayout.LabelField("상단바도 없는 제일 단순한 윈도우, 종료할때 내부 스크립트로 수동으로 꺼야함");
        //! ESC누르면 닫음
        if (Event.current.keyCode == KeyCode.Escape)
        {
            Close();
        }
    }
}

 

PopupWindow - Popup과 동일하나 특정 UI 위에 띄우는 용도

   static CustomEditor_PopupWindow Inst_Editor_PopupWindow = null;
    //! Popup과 동일하나 특정 UI 위에 띄우는 용도 
    [MenuItem("CustomEditor/EditorWindow_PopupWindow")]
    static void EditorWindow_PopupWindow()
    {
        if (Inst_Editor_PopupWindow == null)
        {
            Inst_Editor_PopupWindow = CreateInstance<CustomEditor_PopupWindow>();
        }
        Inst_Editor_PopupWindow.Show();
    }

public class CustomEditor_PopupWindow : EditorWindow
{
    ExamplePopupWindow m_pPopupwindow = null;
    void OnGUI()
    {
        EditorGUILayout.LabelField("Popup과 동일하나 특정 UI 위에 띄우는 용도 ");
        //! ESC누르면 닫음
        if (Event.current.keyCode == KeyCode.Escape)
        {
            Close();
        }
        if (GUILayout.Button("Open PopupWindow", GUILayout.Width(128)))
        {
            //! 해당 버튼 위치에 Rect 값 설정
            Rect activatorRect = GUILayoutUtility.GetLastRect();
            if (m_pPopupwindow == null) m_pPopupwindow = new ExamplePopupWindow();
            PopupWindow.Show(activatorRect, m_pPopupwindow);
        }
    }
}

 

 

DropDown - Popup과 동일하나 창이 모니터 밖으로 튀어 나올때 자동으로 보정됨

 static CustomEditor_DropDown Inst_Editor_DropDown = null;
    //! Popup과 동일하나 창이 모니터 밖으로 튀어나올떄 자동으로 보정해줌
    [MenuItem("CustomEditor/EditorWindow_DropDown")]
    static void EditorWindow_DropDown()
    {
        if (Inst_Editor_DropDown == null)
        {
            Inst_Editor_DropDown = CreateInstance<CustomEditor_DropDown>();
        }

        Vector2 pSpawnPos = new Vector2(700, 150);
        Vector2 windowSize = new Vector2(600, 500);
        Rect buttonRect = new Rect(pSpawnPos.x, pSpawnPos.y - windowSize.y, windowSize.x, windowSize.y);
       
        Inst_Editor_DropDown.ShowAsDropDown(buttonRect, windowSize);
    }
    
    public class CustomEditor_DropDown : EditorWindow
{
    void OnGUI()
    {
        EditorGUILayout.LabelField("Popup과 동일하나 창이 모니터 밖으로 튀어나올떄 자동으로 보정해줌");
        //! ESC누르면 닫음
        if (Event.current.keyCode == KeyCode.Escape)
        {
            Close();
        }
    }
}

 

 

ScriptableWizard - 먼가 특수한 Window

    static CustomEditor_ScripttableWizard Inst_Editor_ScripttableWizard = null;
    //! ScriptableWizard
    [MenuItem("CustomEditor/EditorWindow_ScriptableWizard")]
    static void EditorWindow_ScriptableWizard()
    {
        if (Inst_Editor_ScripttableWizard == null)
        {
            Inst_Editor_ScripttableWizard = CreateInstance<CustomEditor_ScripttableWizard>();
        }
        CustomEditor_ScripttableWizard.DisplayWizard<CustomEditor_ScripttableWizard>("Example Wizard", "Create", "Other(아무이름적으면됨)");
    }


public class CustomEditor_ScripttableWizard : ScriptableWizard
{
    //! 해당 변수가 Inspector뜨듯이 창에 뜸
    public string sName;
    public int nLevel;
    
    //! 창이 소환될때, 내부 값이 바뀔때 호출되는 Callback
    void OnWizardUpdate()
    {
        Debug.Log("OnWizardUpdate");
    }

    //! Create버튼 눌렀을때 Callback
    void OnWizardCreate()
    {
        Debug.Log("OnWizardCreate");
    }

    //! Create버튼 말고 다른 버튼 눌렀을때 Callback
    void OnWizardOtherButton()
    {
        Debug.Log("OnWizardOtherButton");
    }

    //! GUI함수를 만들면 위에 변수들이 나타나지 않게됨(GUI로 처리해야함)
   /* protected override bool DrawWizardGUI()
    {
        EditorGUILayout.LabelField("Label");
        //false 를 반환하면 OnWizardUpdate를 호출하지 않음
        return true;
    }*/
}

 

 

GUIWindow - 특정 Window 위에 띄울 수 있는 GUI

 static CustomEditor_SceneGUIWindow Inst_Editor_SceneGUIWindow = null;
    //! 특정 Window위에 띄울 수 있는 GUI로 이 코드는 SceneView에 올림
    [MenuItem("CustomEditor/EditorWindow_SceneGUIWindow")]
    static void EditorWindow_SceneGUIWindow()
    {
        if (Inst_Editor_SceneGUIWindow == null)
        {
            Inst_Editor_SceneGUIWindow = CreateInstance<CustomEditor_SceneGUIWindow>();
        }
        Inst_Editor_SceneGUIWindow.Enable_SceneGUI();
    }



public class CustomEditor_SceneGUIWindow : EditorWindow
{
    public void Enable_SceneGUI()
    {
        SceneView.onSceneGUIDelegate = SceneViewGUI;
        if (SceneView.lastActiveSceneView) SceneView.lastActiveSceneView.Repaint();
    }

    public void Disable_SceneGUI()
    {
        SceneView.onSceneGUIDelegate = null;
        if (SceneView.lastActiveSceneView) SceneView.lastActiveSceneView.Repaint();
    }

    void SceneViewGUI(SceneView sceneView)
    {
        Handles.BeginGUI();
        EditorGUILayout.LabelField("SceneView GUI Test");
        if (GUILayout.Button("Disable SceneView Button", GUILayout.Width(228)))
        {
            Debug.Log("SceneView ButtonClick");
            Disable_SceneGUI();
        }
        Handles.EndGUI();
    }
}

 

 


풀 소스 + 추가 응용

#if UNITY_EDITOR
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;


public static class CustomEditor_Function
{
    public static void SetWindowSize<T>(ref T pWindow, Vector2 pSize, bool bStaticSize = false) where T : EditorWindow
    {
        Rect pCurrentRect = pWindow.position;
        pCurrentRect.width = pSize.x;
        pCurrentRect.height = pSize.y;
        pWindow.position = pCurrentRect;

        if (bStaticSize==true)
        {
            Vector2 pStaticSize = new Vector2(pSize.x, pSize.y);
            SetWindowSize(ref pWindow, pStaticSize, pStaticSize);
        }
    }

    public static void SetWindowSize<T>(ref T pWindow, Vector2 pMinSize, Vector2 pMaxSize) where T : EditorWindow
    {
        pWindow.maxSize = pMaxSize;
        pWindow.minSize = pMinSize;
    }

    public static void SetWindowPosition<T>(ref T pWindow, Vector2 pPos) where T : EditorWindow
    {
        Rect pCurrentRect = pWindow.position;
        pCurrentRect.x = pPos.x;
        pCurrentRect.y = pPos.y;
        pWindow.position = pCurrentRect;
    }
}



public class CustomEditorTest : EditorWindow
{
    static CustomEditor_Window Inst_Editor_Window = null;
    //! 일반적인 윈도우
    [MenuItem("CustomEditor/EditorWindow")]
    static void EditorWindow()
    {
        if (Inst_Editor_Window == null)
        {
            Inst_Editor_Window = GetWindow<CustomEditor_Window>(typeof(CustomEditor_Window));
        }
        CustomEditor_Function.SetWindowSize(ref Inst_Editor_Window, new Vector2(300.0f, 300.0f), false);
        CustomEditor_Function.SetWindowPosition(ref Inst_Editor_Window, new Vector2(300.0f, 300.0f));
        Inst_Editor_Window.Show();
    }

   
    //! 일반 윈도우를 특정 탭옆에 소환하기
    [MenuItem("CustomEditor/EditorWindow_AddToSceneView")]
    static void EditorWindow_AddToSceneView()
    {
        if (Inst_Editor_Window == null)
        {
            Inst_Editor_Window = GetWindow<CustomEditor_Window>(typeof(SceneView));
        }
        Inst_Editor_Window.Show();
    }


    static CustomEditor_AuxWindow Inst_Editor_AuxWindow = null;
    //! 일반 윈도우, 포커스가 다른곳으로 되면 자동으로 종료됨
    [MenuItem("CustomEditor/EditorWindow_AuxWindow")]
    static void EditorWindow_AuxWindow()
    {
        if (Inst_Editor_AuxWindow == null)
        {
            Inst_Editor_AuxWindow = CreateInstance<CustomEditor_AuxWindow>();
        }
        Inst_Editor_AuxWindow.ShowAuxWindow();
    }


    static CustomEditor_Utility Inst_Editor_Utility = null;
    //! 유틸리티 윈도우, 일반 윈도우와 동일하지만 항상 소팅이 맨앞에 보이게됨
    [MenuItem("CustomEditor/EditorWindow_Utility")]
    static void EditorWindow_Utility()
    {
        if (Inst_Editor_Utility == null)
        {
            Inst_Editor_Utility = CreateInstance<CustomEditor_Utility>();
        }
        Inst_Editor_Utility.ShowUtility();
    }

    static CustomEditor_Popup Inst_Editor_Popup = null;
    //! 상단바도 없는 제일 단순한 윈도우, 종료할때 내부 스크립트로 수동으로 꺼야함
    [MenuItem("CustomEditor/EditorWindow_Popup")]
    static void EditorWindow_Popup()
    {
        if (Inst_Editor_Popup == null)
        {
            Inst_Editor_Popup = CreateInstance<CustomEditor_Popup>();
        }
        Inst_Editor_Popup.ShowPopup();
    }

    static CustomEditor_PopupWindow Inst_Editor_PopupWindow = null;
    //! Popup과 동일하나 특정 UI 위에 띄우는 용도 
    [MenuItem("CustomEditor/EditorWindow_PopupWindow")]
    static void EditorWindow_PopupWindow()
    {
        if (Inst_Editor_PopupWindow == null)
        {
            Inst_Editor_PopupWindow = CreateInstance<CustomEditor_PopupWindow>();
        }
        Inst_Editor_PopupWindow.Show();
    }

    static CustomEditor_DropDown Inst_Editor_DropDown = null;
    //! Popup과 동일하나 창이 모니터 밖으로 튀어나올떄 자동으로 보정해줌
    [MenuItem("CustomEditor/EditorWindow_DropDown")]
    static void EditorWindow_DropDown()
    {
        if (Inst_Editor_DropDown == null)
        {
            Inst_Editor_DropDown = CreateInstance<CustomEditor_DropDown>();
        }

        Vector2 pSpawnPos = new Vector2(700, 150);
        Vector2 windowSize = new Vector2(600, 500);
        Rect buttonRect = new Rect(pSpawnPos.x, pSpawnPos.y - windowSize.y, windowSize.x, windowSize.y);
       
        Inst_Editor_DropDown.ShowAsDropDown(buttonRect, windowSize);
    }

    static CustomEditor_ScripttableWizard Inst_Editor_ScripttableWizard = null;
    //! ScriptableWizard
    [MenuItem("CustomEditor/EditorWindow_ScriptableWizard")]
    static void EditorWindow_ScriptableWizard()
    {
        if (Inst_Editor_ScripttableWizard == null)
        {
            Inst_Editor_ScripttableWizard = CreateInstance<CustomEditor_ScripttableWizard>();
        }
        CustomEditor_ScripttableWizard.DisplayWizard<CustomEditor_ScripttableWizard>("Example Wizard", "Create", "Other(아무이름적으면됨)");
    }

    static CustomEditor_SceneGUIWindow Inst_Editor_SceneGUIWindow = null;
    //! 특정 Window위에 띄울 수 있는 GUI로 이 코드는 SceneView에 올림
    [MenuItem("CustomEditor/EditorWindow_SceneGUIWindow")]
    static void EditorWindow_SceneGUIWindow()
    {
        if (Inst_Editor_SceneGUIWindow == null)
        {
            Inst_Editor_SceneGUIWindow = CreateInstance<CustomEditor_SceneGUIWindow>();
        }
        Inst_Editor_SceneGUIWindow.Enable_SceneGUI();
    }
}

public class CustomEditor_Window : EditorWindow
{
    void OnGUI()
    {
        EditorGUILayout.LabelField("일반적인 윈도우");
    }
}

public class CustomEditor_AuxWindow : EditorWindow
{
    void OnGUI()
    {
        EditorGUILayout.LabelField("일반 윈도우, 포커스가 다른곳으로 되면 자동으로 종료됨");
    }
}

public class CustomEditor_Utility : EditorWindow
{
    void OnGUI()
    {
        EditorGUILayout.LabelField("유틸리티 윈도우, 일반 윈도우와 동일하지만 항상 소팅이 맨앞에 보이게됨");
    }
}

public class CustomEditor_Popup : EditorWindow
{
    void OnGUI()
    {
        EditorGUILayout.LabelField("상단바도 없는 제일 단순한 윈도우, 종료할때 내부 스크립트로 수동으로 꺼야함");
        //! ESC누르면 닫음
        if (Event.current.keyCode == KeyCode.Escape)
        {
            Close();
        }
    }
}

public class CustomEditor_PopupWindow : EditorWindow
{
    ExamplePopupWindow m_pPopupwindow = null;
    void OnGUI()
    {
        EditorGUILayout.LabelField("Popup과 동일하나 특정 UI 위에 띄우는 용도 ");
        //! ESC누르면 닫음
        if (Event.current.keyCode == KeyCode.Escape)
        {
            Close();
        }
        if (GUILayout.Button("Open PopupWindow", GUILayout.Width(128)))
        {
            //! 해당 버튼 위치에 Rect 값 설정
            Rect activatorRect = GUILayoutUtility.GetLastRect();
            if (m_pPopupwindow == null) m_pPopupwindow = new ExamplePopupWindow();
            PopupWindow.Show(activatorRect, m_pPopupwindow);
        }
    }
}

public class CustomEditor_DropDown : EditorWindow
{
    void OnGUI()
    {
        EditorGUILayout.LabelField("Popup과 동일하나 창이 모니터 밖으로 튀어나올떄 자동으로 보정해줌");
        //! ESC누르면 닫음
        if (Event.current.keyCode == KeyCode.Escape)
        {
            Close();
        }
    }
}

public class CustomEditor_ScripttableWizard : ScriptableWizard
{
    //! 해당 변수가 Inspector뜨듯이 창에 뜸
    public string sName;
    public int nLevel;
    
    //! 창이 소환될때, 내부 값이 바뀔때 호출되는 Callback
    void OnWizardUpdate()
    {
        Debug.Log("OnWizardUpdate");
    }

    //! Create버튼 눌렀을때 Callback
    void OnWizardCreate()
    {
        Debug.Log("OnWizardCreate");
    }

    //! Create버튼 말고 다른 버튼 눌렀을때 Callback
    void OnWizardOtherButton()
    {
        Debug.Log("OnWizardOtherButton");
    }

    //! GUI함수를 만들면 위에 변수들이 나타나지 않게됨(GUI로 처리해야함)
   /* protected override bool DrawWizardGUI()
    {
        EditorGUILayout.LabelField("Label");
        //false 를 반환하면 OnWizardUpdate를 호출하지 않음
        return true;
    }*/
}



public class ExamplePopupWindow : PopupWindowContent
{
    public override void OnGUI(Rect rect)
    {
        EditorGUILayout.LabelField("TestPopupWindow");
    }

    //! 창 켜질때 호출
    public override void OnOpen()
    {
        Debug.Log("Popup Window _Open");
    }

    //! 창 꺼질때 호출
    public override void OnClose()
    {
        Debug.Log("Popup Window _Close");
    }

    //! Popup window 사이즈 설정
    public override Vector2 GetWindowSize()
    {
        return new Vector2(300, 100);
    }
}

public class CustomEditor_SceneGUIWindow : EditorWindow
{
    public void Enable_SceneGUI()
    {
        SceneView.onSceneGUIDelegate = SceneViewGUI;
        if (SceneView.lastActiveSceneView) SceneView.lastActiveSceneView.Repaint();
    }

    public void Disable_SceneGUI()
    {
        SceneView.onSceneGUIDelegate = null;
        if (SceneView.lastActiveSceneView) SceneView.lastActiveSceneView.Repaint();
    }

    void SceneViewGUI(SceneView sceneView)
    {
        Handles.BeginGUI();
        EditorGUILayout.LabelField("SceneView GUI Test");
        if (GUILayout.Button("Disable SceneView Button", GUILayout.Width(228)))
        {
            Debug.Log("SceneView ButtonClick");
            Disable_SceneGUI();
        }
        Handles.EndGUI();
    }
}

#endif

 


WRITTEN BY
CatDarkGame
Technical Artist dhwlgn12@gmail.com

,