OdinEditorWindow

Base class for creating editor windows using Odin.

namespace Sirenix.OdinInspector.Editor
{
[Sirenix.OdinInspector.ShowOdinSerializedPropertiesInInspectorAttribute]
public class OdinEditorWindow : UnityEditor.EditorWindow, UnityEngine.ISerializationCallbackReceiver
}

Requirements

Namespace: Sirenix.OdinInspector.Editor
Assembly: Sirenix.OdinInspector
Version: 1.0.6.1

See Also

Static Methods

Return Type Definition Description
OdinEditorWindow CreateOdinEditorWindowInstanceForObject(Object) Creates an editor window instance for the specified object, without opening the window.
OdinEditorWindow InspectObject(Object) Pops up an editor window for the given object.
OdinEditorWindow InspectObjectInDropDown(Object)

Pops up an editor window for the given object in a drop-down window which closes when it loses its focus.

Protip: You can subscribe to OnClose if you want to know when that occurs.

OdinEditorWindow InspectObjectInDropDown(Object, float)

Pops up an editor window for the given object in a drop-down window which closes when it loses its focus.

Protip: You can subscribe to OnClose if you want to know when that occurs.

OdinEditorWindow InspectObjectInDropDown(Object, float, float)

Pops up an editor window for the given object in a drop-down window which closes when it loses its focus.

Protip: You can subscribe to OnClose if you want to know when that occurs.

OdinEditorWindow InspectObjectInDropDown(Object, Rect, float)

Pops up an editor window for the given object in a drop-down window which closes when it loses its focus. This particular overload uses a few frames to calculate the height of the content before showing the window with a height that matches its content.

Protip: You can subscribe to OnClose if you want to know when that occurs.

OdinEditorWindow InspectObjectInDropDown(Object, Rect, Vector2)

Pops up an editor window for the given object in a drop-down window which closes when it loses its focus.

Protip: You can subscribe to OnClose if you want to know when that occurs.

OdinEditorWindow InspectObjectInDropDown(Object, Vector2)

Pops up an editor window for the given object in a drop-down window which closes when it loses its focus.

Protip: You can subscribe to OnClose if you want to know when that occurs.

OdinEditorWindow InspectObjectInDropDown(Object, Vector2, float)

Pops up an editor window for the given object in a drop-down window which closes when it loses its focus.

Protip: You can subscribe to OnClose if you want to know when that occurs.

Events

Definition Description
OnBeginGUI Occurs at the beginning the OnGUI method.
OnClose Occurs when the window is closed.
OnEndGUI Occurs at the end the OnGUI method.

Properties

Return Type Definition Description
ImmutableList<Object> CurrentDrawingTargets At the start of each OnGUI event when in the Layout event, the GetTargets() method is called and cached into a list which you can access from here.
float DefaultEditorPreviewHeight Gets the default preview height for Unity editors.
float DefaultLabelWidth Gets the label width to be used. Values between 0 and 1 are treated as percentages, and values above as pixels.
bool DrawUnityEditorPreview Gets a value indicating whether the window should draw a Unity editor preview, if possible.
PropertyTree PropertyTree The Odin property tree drawn.
bool UseScrollView Gets a value indicating whether the window should draw a scroll view.
Vector4 WindowPadding Gets or sets the window padding. x = left, y = right, z = top, w = bottom.

Methods

Return Type Definition Description
void DrawEditor(int) Draws the editor for the this.CurrentDrawingTargets[index].
void DrawEditorPreview(int, float) Uses the Rect) method to draw a preview for the this.CurrentDrawingTargets[index].
Object GetTarget() Gets the target which which the window is supposed to draw. By default it simply returns the editor window instance itself. By default, this method is called by GetTargets()().
IEnumerable<Object> GetTargets() Gets the targets to be drawn by the editor window. By default this simply yield returns the GetTarget() method.
void OnAfterDeserialize() See ISerializationCallbackReceiver.OnBeforeSerialize for documentation on how to use this method.
void OnBeforeSerialize() Implement this method to receive a callback after unity serialized your object.
void OnBeginDrawEditors() Called after all editors for the CurrentDrawingTargets has been drawn.
void OnDestroy() Called when the window is destroyed. Remember to call base.OnDestroy();
void OnEnable() Called when the window is enabled. Remember to call base.OnEnable();
void OnEndDrawEditors() Called before starting to draw all editors for the CurrentDrawingTargets.
void OnGUI() Draws the Odin Editor Window.

Example

public class SomeWindow : OdinEditorWindow
{
    [MenuItem("My Game/Some Window")]
    private static void OpenWindow()
    {
        GetWindow<SomeWindow>().Show();
    }

    [Button(ButtonSizes.Large)]
    public void SomeButton() { }

    [TableList]
    public SomeType[] SomeTableData;
}

Example

public class DrawSomeSingletonInAnEditorWindow : OdinEditorWindow
{
    [MenuItem("My Game/Some Window")]
    private static void OpenWindow()
    {
        GetWindow<DrawSomeSingletonInAnEditorWindow>().Show();
    }

    protected override object GetTarget()
    {
        return MySingleton.Instance;
    }
}

Example

private void InspectObjectInWindow()
{
    OdinEditorWindow.InspectObject(someObject);
}

private void InspectObjectInDropDownWithAutoHeight()
{
    var btnRect = GUIHelper.GetCurrentLayoutRect();
    OdinEditorWindow.InspectObjectInDropDown(someObject, btnRect, btnRect.width);
}

private void InspectObjectInDropDown()
{
    var btnRect = GUIHelper.GetCurrentLayoutRect();
    OdinEditorWindow.InspectObjectInDropDown(someObject, btnRect, new Vector2(btnRect.width, 100));
}

private void InspectObjectInACenteredWindow()
{
    var window = OdinEditorWindow.InspectObject(someObject);
    window.position = GUIHelper.GetEditorWindowRect().AlignCenter(270, 200);
}

private void OtherStuffYouCanDo()
{
    var window = OdinEditorWindow.InspectObject(this.someObject);

    window.position = GUIHelper.GetEditorWindowRect().AlignCenter(270, 200);
    window.titleContent = new GUIContent("Custom title", EditorIcons.RulerRect.Active);
    window.OnClose += () => Debug.Log("Window Closed");
    window.OnBeginGUI += () => GUILayout.Label("-----------");
    window.OnEndGUI += () => GUILayout.Label("-----------");
}