Version 3.3.1.2

OdinEditorWindow class

Namespace: Sirenix.OdinInspector.Editor
Assembly: Sirenix.OdinInspector.Editor
[ShowOdinSerializedPropertiesInInspector]
public class OdinEditorWindow : EditorWindow, ISerializationCallbackReceiver
Base class for creating editor windows using Odin.
Inheritance
  • System.Object
  • OdinEditorWindow
Implements
  • UnityEngine.ISerializationCallbackReceiver
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("-----------");
}

Constructors

OdinEditorWindow()
public OdinEditorWindow()

Fields

MAX_DROPDOWN_HEIGHT
public const int MAX_DROPDOWN_HEIGHT = 600
MIN_DROPDOWN_HEIGHT
public const int MIN_DROPDOWN_HEIGHT = 200

Properties

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.
protected ImmutableList<object> CurrentDrawingTargets { get; }
DefaultEditorPreviewHeight
Gets the default preview height for Unity editors.
public virtual float DefaultEditorPreviewHeight { get; set; }
DefaultLabelWidth
Gets the label width to be used. Values between 0 and 1 are treated as percentages, and values above as pixels.
public virtual float DefaultLabelWidth { get; set; }
DrawUnityEditorPreview
Gets a value indicating whether the window should draw a Unity editor preview, if possible.
public virtual bool DrawUnityEditorPreview { get; set; }
UseScrollView
Gets a value indicating whether the window should draw a scroll view.
public virtual bool UseScrollView { get; set; }
WindowPadding
Gets or sets the window padding. x = left, y = right, z = top, w = bottom.
public virtual Vector4 WindowPadding { get; set; }

Methods

CreateOdinEditorWindowInstanceForObject(Object)
Creates an editor window instance for the specified object, without opening the window.
public static OdinEditorWindow CreateOdinEditorWindowInstanceForObject(object obj)
Parameters
System.Object obj

DrawEditor(Int32)
Draws the editor for the this.CurrentDrawingTargets[index].
protected virtual void DrawEditor(int index)
Parameters
System.Int32 index

DrawEditorPreview(Int32, Single)
Uses the UnityEditor.Editor.DrawPreview(UnityEngine.Rect) method to draw a preview for the this.CurrentDrawingTargets[index].
protected virtual void DrawEditorPreview(int index, float height)
Parameters
System.Int32 index

System.Single height

DrawEditors()
Calls DrawEditor(index) for each of the currently drawing targets.
protected virtual void DrawEditors()
EnableAutomaticHeightAdjustment(Int32, Boolean)
Measures the GUILayout content height and adjusts the window height accordingly. Note that this feature becomes pointless if any layout group expands vertically.
protected void EnableAutomaticHeightAdjustment(int maxHeight, bool retainInitialWindowPosition)
Parameters
System.Int32 maxHeight

The max height of the window.

System.Boolean retainInitialWindowPosition

When the window height expands below the screen bounds, it will move the window upwards when needed, enabling this will move it back down when the window height is decreased.

EnsureEditorsAreReady()
protected void EnsureEditorsAreReady()
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()().
protected virtual object GetTarget()
Returns
System.Object

GetTargets()
Gets the targets to be drawn by the editor window. By default this simply yield returns the GetTarget() method.
protected virtual IEnumerable<object> GetTargets()
Returns
System.Collections.Generic.IEnumerable<System.Object>

Initialize()
Initialize get called by OnEnable and by OnGUI after assembly reloads which often happens when you recompile or enter and exit play mode.
protected virtual void Initialize()
InspectObject(OdinEditorWindow, Object)
Inspects the object using an existing OdinEditorWindow.
public static OdinEditorWindow InspectObject(OdinEditorWindow window, object obj)
Parameters
OdinEditorWindow window

System.Object obj

InspectObject(Object)
Pops up an editor window for the given object.
public static OdinEditorWindow InspectObject(object obj)
Parameters
System.Object obj

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.

public static OdinEditorWindow InspectObjectInDropDown(object obj)
Parameters
System.Object obj

InspectObjectInDropDown(Object, Single)

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.

public static OdinEditorWindow InspectObjectInDropDown(object obj, float windowWidth)
Parameters
System.Object obj

System.Single windowWidth

InspectObjectInDropDown(Object, Single, Single)

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.

public static OdinEditorWindow InspectObjectInDropDown(object obj, float width, float height)
Parameters
System.Object obj

System.Single width

System.Single height

InspectObjectInDropDown(Object, Rect, Single)

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.

public static OdinEditorWindow InspectObjectInDropDown(object obj, Rect btnRect, float windowWidth)
Parameters
System.Object obj

UnityEngine.Rect btnRect

System.Single windowWidth

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.

public static OdinEditorWindow InspectObjectInDropDown(object obj, Rect btnRect, Vector2 windowSize)
Parameters
System.Object obj

UnityEngine.Rect btnRect

UnityEngine.Vector2 windowSize

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.

public static OdinEditorWindow InspectObjectInDropDown(object obj, Vector2 position)
Parameters
System.Object obj

UnityEngine.Vector2 position

InspectObjectInDropDown(Object, Vector2, Single)

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.

public static OdinEditorWindow InspectObjectInDropDown(object obj, Vector2 position, float windowWidth)
Parameters
System.Object obj

UnityEngine.Vector2 position

System.Single windowWidth

OnAfterDeserialize()
See ISerializationCallbackReceiver.OnBeforeSerialize for documentation on how to use this method.
protected virtual void OnAfterDeserialize()
OnBeforeSerialize()
Implement this method to receive a callback after unity serialized your object.
protected virtual void OnBeforeSerialize()
OnBeginDrawEditors()
Called after all editors for the CurrentDrawingTargets has been drawn.
protected virtual void OnBeginDrawEditors()
OnDestroy()
Called when the window is destroyed. Remember to call base.OnDestroy();
protected virtual void OnDestroy()
OnDisable()
protected virtual void OnDisable()
OnEnable()
Called when the window is enabled. Remember to call base.OnEnable();
protected virtual void OnEnable()
OnEndDrawEditors()
Called before starting to draw all editors for the CurrentDrawingTargets.
protected virtual void OnEndDrawEditors()
OnImGUI()
protected virtual void OnImGUI()
ShowToast(ToastPosition, SdfIconType, String, Color, Single)
public void ShowToast(ToastPosition toastPosition, SdfIconType icon, string text, Color color, float duration)
Parameters
ToastPosition toastPosition

SdfIconType icon

System.String text

UnityEngine.Color color

System.Single duration

UpdateEditors()
protected void UpdateEditors()

Events

OnBeginGUI
Occurs at the beginning the OnGUI method.
public event Action OnBeginGUI
OnClose
Occurs when the window is closed.
public event Action OnClose
OnEndGUI
Occurs at the end the OnGUI method.
public event Action OnEndGUI