Version 2.1.0.0

GUIHelper class

Namespace: Sirenix.Utilities.Editor
Assembly: Sirenix.Utilities.Editor
public static class GUIHelper
Various helper function for GUI.
Inheritance
  • System.Object
  • GUIHelper

Properties

ActualLabelWidth
Gets or sets the actual EditorGUIUtility.LabelWidth, regardless of the current hierarchy mode or context width.
public static float ActualLabelWidth { get; set; }
BetterContextWidth
Odin will set this for you whenever an Odin property tree is drawn. But if you're using BetterLabelWidth and BetterContextWidth without Odin, then you need to set BetterContextWidth in the beginning of each GUIEvent.
public static float BetterContextWidth { get; set; }
BetterLabelWidth
Unity EditorGUIUtility.labelWidth only works reliablly in Repaint events. BetterLabelWidth does a better job at giving you the correct LabelWidth in non-repaint events.
public static float BetterLabelWidth { get; set; }
ContextWidth
Gets the current editor gui context width. Only set these if you know what it does.
public static float ContextWidth { get; set; }
CurrentIndentAmount
Gets the current indent amount.
public static float CurrentIndentAmount { get; }
CurrentWindow
Gets the current editor window.
public static EditorWindow CurrentWindow { get; }
CurrentWindowBorderSize
Gets the size of the current window border.
public static RectOffset CurrentWindowBorderSize { get; }
CurrentWindowHasFocus
Gets a value indicating whether the current editor window is focused.
public static bool CurrentWindowHasFocus { get; }
CurrentWindowInstanceID
Gets the ID of the current editor window.
public static int CurrentWindowInstanceID { get; }
EditorScreenPointOffset
Gets the editor screen point offset.
public static Vector2 EditorScreenPointOffset { get; }
IsBoldLabel
Gets or sets a value indicating whether labels are currently bold.
public static bool IsBoldLabel { get; set; }
IsDrawingDictionaryKey
Whether the inspector is currently in the progress of drawing a dictionary key.
public static bool IsDrawingDictionaryKey { get; }
MouseScreenPosition
Gets the mouse screen position.
public static Vector2 MouseScreenPosition { get; }
RepaintRequested
Gets a value indicating whether a repaint has been requested.
public static bool RepaintRequested { get; }

Methods

BeginDrawToNothing()
Hides the following draw calls. Remember to call EndDrawToNothing() when done.
public static void BeginDrawToNothing()
BeginIgnoreInput()
Ignores input on following GUI calls. Remember to end with EndIgnoreInput().
public static void BeginIgnoreInput()
BeginLayoutMeasuring()
Begins the layout measuring. Remember to end with EndLayoutMeasuring().
public static void BeginLayoutMeasuring()
ClearRepaintRequest()
Clears the repaint request.
public static void ClearRepaintRequest()
DisplaySmartUpdatingCancellableProgressBar(String, String, Single, Int32, Int32)
public static bool DisplaySmartUpdatingCancellableProgressBar(string title, string details, float progress, int updateIntervalByMS = 200, int updateIntervalByCall = 50)
Parameters
System.String title

System.String details

System.Single progress

System.Int32 updateIntervalByMS

System.Int32 updateIntervalByCall

Returns
System.Boolean

DisplaySmartUpdatingProgressBar(String, String, Single, Int32, Int32)
public static void DisplaySmartUpdatingProgressBar(string title, string details, float progress, int updateIntervalByMS = 200, int updateIntervalByCall = 50)
Parameters
System.String title

System.String details

System.Single progress

System.Int32 updateIntervalByMS

System.Int32 updateIntervalByCall

EndDrawToNothing()
Unhides the following draw calls after having called BeginDrawToNothing().
public static void EndDrawToNothing()
EndIgnoreInput()
Ends the ignore input started by BeginIgnoreInput().
public static void EndIgnoreInput()
EndLayoutMeasuring()
Ends the layout measuring started by BeginLayoutMeasuring()
public static Rect EndLayoutMeasuring()
Returns
UnityEngine.Rect

The measured rect.

GetAssetThumbnail(Object, Type, Boolean)
Gets the best thumbnail icon given the provided arguments provided.
public static Texture2D GetAssetThumbnail(Object obj, Type type, bool preferObjectPreviewOverFileIcon)
Parameters
UnityEngine.Object obj

System.Type type

System.Boolean preferObjectPreviewOverFileIcon

Returns
UnityEngine.Texture2D

GetBoldDefaultFont()
Gets the bold default font.
public static bool GetBoldDefaultFont()
Returns
System.Boolean

GetCurrentLayoutRect()
Gets the current layout rect.
public static Rect GetCurrentLayoutRect()
Returns
UnityEngine.Rect

The current layout rect.

GetCurrentLayoutStyle()
Gets the current layout rect.
public static GUIStyle GetCurrentLayoutStyle()
Returns
UnityEngine.GUIStyle

The current layout rect.

GetEditorWindowRect()
Not yet documented.
public static Rect GetEditorWindowRect()
Returns
UnityEngine.Rect

GetPlaymodeTint()
Gets the playmode color tint.
public static Color GetPlaymodeTint()
Returns
UnityEngine.Color

The playmode color tint.

GetTemporaryContext<TValue>(Object)
Gets a temporary value context.
public static GUIContext<TValue> GetTemporaryContext<TValue>(object key)
    where TValue : class, new()
Parameters
System.Object key

The key for the context.

Returns
GUIContext<TValue>

GUIConfig for the specified key.

Type Parameters
TValue

The type of the value.

GetTemporaryContext<TValue>(Object, TValue)
Gets a temporary context.
public static GUIContext<TValue> GetTemporaryContext<TValue>(object key, TValue defaultValue)
    where TValue : struct
Parameters
System.Object key

Key for the context.

TValue defaultValue

Default value of the context.

Returns
GUIContext<TValue>

Type Parameters
TValue

GetTemporaryContext<TValue>(Object, Int32)
Gets a temporary value context.
public static GUIContext<TValue> GetTemporaryContext<TValue>(object key, int id)
    where TValue : class, new()
Parameters
System.Object key

The key for the config.

System.Int32 id

The ID for the config.

Returns
GUIContext<TValue>

GUIConfig for the specified key and ID.

Type Parameters
TValue

The type of the value.

GetTemporaryContext<TValue>(Object, Int32, TValue)
Gets a temporary context.
public static GUIContext<TValue> GetTemporaryContext<TValue>(object key, int id, TValue defaultValue)
    where TValue : struct
Parameters
System.Object key

Key for the context.

System.Int32 id

Id for the context.

TValue defaultValue

Default value of the context.

Returns
GUIContext<TValue>

Type Parameters
TValue

GetTemporaryContext<TValue>(Object, Object)
Gets a temporary value context.
public static GUIContext<TValue> GetTemporaryContext<TValue>(object primaryKey, object secondaryKey)
    where TValue : class, new()
Parameters
System.Object primaryKey

The primary key.

System.Object secondaryKey

The secondary key.

Returns
GUIContext<TValue>

GUIConfig for the specified primary and secondary key.

Type Parameters
TValue

The type of the value.

GetTemporaryContext<TValue>(Object, Object, TValue)
Gets a temporary context.
public static GUIContext<TValue> GetTemporaryContext<TValue>(object primaryKey, object secondaryKey, TValue defaultValue)
    where TValue : struct
Parameters
System.Object primaryKey

Primary key for the context.

System.Object secondaryKey

Secondary key for the context.

TValue defaultValue

Default value of the context.

Returns
GUIContext<TValue>

Type Parameters
TValue

GetTemporaryContext<TValue>(Object, String)
Gets a temporary value context.
public static GUIContext<TValue> GetTemporaryContext<TValue>(object key, string name)
    where TValue : class, new()
Parameters
System.Object key

The key for the config.

System.String name

The name of the config.

Returns
GUIContext<TValue>

GUIConfig for the specified key and name.

Type Parameters
TValue

The type of the config value.

GetTemporaryContext<TValue>(Object, String, TValue)
Gets a temporary context.
public static GUIContext<TValue> GetTemporaryContext<TValue>(object key, string name, TValue defaultValue)
    where TValue : struct
Parameters
System.Object key

Key for the context.

System.String name

Name for the context.

TValue defaultValue

Default value of the context.

Returns
GUIContext<TValue>

Type Parameters
TValue

GetTemporaryNullableContext<TValue>(Object)
Gets a temporary nullable value context.
public static GUIContext<TValue> GetTemporaryNullableContext<TValue>(object key)
    where TValue : class
Parameters
System.Object key

Key for the context.

Returns
GUIContext<TValue>

Type Parameters
TValue

GetTemporaryNullableContext<TValue>(Object, Int32)
Gets a temporary nullable value context.
public static GUIContext<TValue> GetTemporaryNullableContext<TValue>(object key, int id)
    where TValue : class
Parameters
System.Object key

Key for context.

System.Int32 id

Id of the context.

Returns
GUIContext<TValue>

Type Parameters
TValue

GetTemporaryNullableContext<TValue>(Object, Object)
Gets a temporary nullable value context.
public static GUIContext<TValue> GetTemporaryNullableContext<TValue>(object primaryKey, object secondaryKey)
    where TValue : class
Parameters
System.Object primaryKey

Primary key for the context.

System.Object secondaryKey

Secondary key for the context.

Returns
GUIContext<TValue>

Type Parameters
TValue

GetTemporaryNullableContext<TValue>(Object, String)
Gets a temporary nullable value context.
public static GUIContext<TValue> GetTemporaryNullableContext<TValue>(object key, string name)
    where TValue : class
Parameters
System.Object key

Key for context.

System.String name

Name for the context.

Returns
GUIContext<TValue>

Type Parameters
TValue

IndentRect(Rect)
Indents the rect by the current indent amount.
public static Rect IndentRect(Rect rect)
Parameters
UnityEngine.Rect rect

The rect to indent.

Returns
UnityEngine.Rect

Indented rect.

IndentRect(ref Rect)
Indents the rect by the current indent amount.
public static void IndentRect(ref Rect rect)
Parameters
UnityEngine.Rect rect

The rect to indent.

IsDockedWindow(EditorWindow)
Determines whether the specified EditorWindow is docked.
public static bool IsDockedWindow(EditorWindow window)
Parameters
UnityEditor.EditorWindow window

The editor window.

Returns
System.Boolean

true if the editor window is docked. Otherwise false.

OpenInspectorWindow(Object)
Opens a new inspector window for the specified object.
public static void OpenInspectorWindow(Object unityObj)
Parameters
UnityEngine.Object unityObj

The unity object.

Exceptions
System.ArgumentNullException

unityObj

PingObject(Object)
public static void PingObject(Object obj)
Parameters
UnityEngine.Object obj

PopColor()
Pops the GUI color pushed by PushColor(Color, Boolean).
public static void PopColor()
PopContentColor()
Pops the content color pushed by PushContentColor(Color, Boolean).
public static void PopContentColor()
PopEventType()
Pops the event type pushed by PopEventType().
public static void PopEventType()
PopFadeGroupDuration()
Pops fade group duration value pushed by PushFadeGroupDuration(Single).
public static void PopFadeGroupDuration()
PopGUIEnabled()
Pops the GUI enabled pushed by PushGUIEnabled(Boolean)
public static void PopGUIEnabled()
PopGUIPositionOffset()
Pops the GUI position offset pushed by PushGUIPositionOffset(Vector2).
public static void PopGUIPositionOffset()
PopHierarchyMode()
Pops the hierarchy mode pushed by .
public static void PopHierarchyMode()
PopIndentLevel()
Pops the indent level pushed by PushIndentLevel(Int32).
public static void PopIndentLevel()
PopIsBoldLabel()
Pops the bold label state pushed by PushIsBoldLabel(Boolean).
public static void PopIsBoldLabel()
PopIsDrawingDictionaryKey()
Pops the state pushed by PushIsDrawingDictionaryKey(Boolean)
public static void PopIsDrawingDictionaryKey()
PopLabelColor()
Pops the label color pushed by PushLabelColor(Color).
public static void PopLabelColor()
PopLabelWidth()
Pops editor gui label widths pushed by PushLabelWidth(Single).
public static void PopLabelWidth()
PopMatrix()
Pops the GUI matrix pushed by PushMatrix(Matrix4x4).
public static void PopMatrix()
PopResponsiveVectorComponentFields()
Pops responsive vector component fields value pushed by PushResponsiveVectorComponentFields(Boolean).
public static void PopResponsiveVectorComponentFields()
PopTabPageSlideAnimationDuration()
Pops tab page slide animation duration value pushed by PushTabPageSlideAnimationDuration(Single).
public static void PopTabPageSlideAnimationDuration()
PushColor(Color, Boolean)
Pushes a color to the GUI color stack. Remember to pop the color with PopColor().
public static void PushColor(Color color, bool blendAlpha = false)
Parameters
UnityEngine.Color color

The color to push the GUI color..

System.Boolean blendAlpha

if set to true blend with alpha.

PushContentColor(Color, Boolean)
Pushes the content color to the stack. Remember to pop with PopContentColor().
public static void PushContentColor(Color color, bool blendAlpha = false)
Parameters
UnityEngine.Color color

The content color to push..

System.Boolean blendAlpha

If set to true blend with alpha.

PushEventType(EventType)
Pushes the event type to the stack. Remember to pop with PopEventType().
public static void PushEventType(EventType eventType)
Parameters
UnityEngine.EventType eventType

The type of event to push.

PushFadeGroupDuration(Single)
Pushes the value to the fade group duration stack. Remeber to pop with PopFadeGroupDuration().
public static void PushFadeGroupDuration(float duration)
Parameters
System.Single duration

PushGUIEnabled(Boolean)
Pushes a state to the GUI enabled stack. Remember to pop the state with PopGUIEnabled().
public static void PushGUIEnabled(bool enabled)
Parameters
System.Boolean enabled

If set to true GUI will be enabled. Otherwise GUI will be disabled.

PushGUIPositionOffset(Vector2)
Pushes the GUI position offset to the stack. Remember to pop with PopGUIPositionOffset().
public static void PushGUIPositionOffset(Vector2 offset)
Parameters
UnityEngine.Vector2 offset

The GUI offset.

PushHierarchyMode(Boolean, Boolean)
Pushes the hierarchy mode to the stack. Remember to pop the state with PopHierarchyMode().
public static void PushHierarchyMode(bool hierarchyMode, bool preserveCurrentLabelWidth = true)
Parameters
System.Boolean hierarchyMode

The hierachy mode state to push.

System.Boolean preserveCurrentLabelWidth

Changing hierachy mode also changes how label-widths are calcualted. By default, we try to keep the current label width.

PushIndentLevel(Int32)
Pushes the indent level to the stack. Remember to pop with PopIndentLevel().
public static void PushIndentLevel(int indentLevel)
Parameters
System.Int32 indentLevel

The indent level to push.

PushIsBoldLabel(Boolean)
Pushes bold label state to the stack. Remember to pop with PopIsBoldLabel().
public static void PushIsBoldLabel(bool isBold)
Parameters
System.Boolean isBold

Value indicating if labels should be bold or not.

PushIsDrawingDictionaryKey(Boolean)
Pushes a state to the IsDrawingDictionaryKey stack. Remember to pop the state with PopIsDrawingDictionaryKey().
public static void PushIsDrawingDictionaryKey(bool enabled)
Parameters
System.Boolean enabled

PushLabelColor(Color)
Pushes the label color to the stack. Remember to pop with PopLabelColor().
public static void PushLabelColor(Color color)
Parameters
UnityEngine.Color color

The label color to push.

PushLabelWidth(Single)
Pushes the width to the editor GUI label width to the stack. Remmeber to Pop with PopLabelWidth().
public static void PushLabelWidth(float labelWidth)
Parameters
System.Single labelWidth

The editor GUI label width to push.

PushMatrix(Matrix4x4)
Pushes a GUI matrix to the stack. Remember to pop with PopMatrix().
public static void PushMatrix(Matrix4x4 matrix)
Parameters
UnityEngine.Matrix4x4 matrix

The GUI matrix to push.

PushResponsiveVectorComponentFields(Boolean)
Pushes the value to the responsive vector component fields stack. Remeber to pop with PopResponsiveVectorComponentFields().
public static void PushResponsiveVectorComponentFields(bool responsive)
Parameters
System.Boolean responsive

PushTabPageSlideAnimationDuration(Single)
Pushes the value to the tab page slide animation duration stack. Remember to pop with PopTabPageSlideAnimationDuration().
public static void PushTabPageSlideAnimationDuration(float duration)
Parameters
System.Single duration

RemoveFocusControl()
An alternative to GUI.FocusControl(null), which does not take focus away from the current GUI.Window.
public static void RemoveFocusControl()
RepaintIfRequested(Editor)
Repaints the editor if a repaint has been requested. If the currently rendering window is not an InspectorWindow, Repaint() will be called on the current window as well.
public static void RepaintIfRequested(this Editor editor)
Parameters
UnityEditor.Editor editor

The editor to repaint.

RepaintIfRequested(EditorWindow)
Repaints the EditorWindow if a repaint has been requested.
public static void RepaintIfRequested(this EditorWindow window)
Parameters
UnityEditor.EditorWindow window

The window to repaint.

RequestRepaint()
Requests a repaint.
public static void RequestRepaint()
RequestRepaint(Int32)
Requests a repaint.
public static void RequestRepaint(int numberOfFramesToRepaint)
Parameters
System.Int32 numberOfFramesToRepaint

SelectObject(Object)
public static void SelectObject(Object obj)
Parameters
UnityEngine.Object obj

TakeGUIScreenshot(Rect)
Takes a screenshot of the GUI within the specified rect.
public static RenderTexture TakeGUIScreenshot(Rect rect)
Parameters
UnityEngine.Rect rect

The rect.

Returns
UnityEngine.RenderTexture

The screenshot as a render texture.

TempContent(String)
Gets a temporary GUIContent with the specified text.
public static GUIContent TempContent(string t)
Parameters
System.String t

The text for the GUIContent.

Returns
UnityEngine.GUIContent

Temporary GUIContent instance.

TempContent(String, String)
Gets a temporary GUIContent with the specified text and tooltip.
public static GUIContent TempContent(string t, string tooltip)
Parameters
System.String t

The text for the GUIContent.

System.String tooltip

The tooltip for the GUIContent.

Returns
UnityEngine.GUIContent

Temporary GUIContent instance.

TempContent(String, Texture, String)
Gets a temporary GUIContent with the specified text, image and tooltip.
public static GUIContent TempContent(string text, Texture image, string tooltip = null)
Parameters
System.String text

The text for the GUIContent.

UnityEngine.Texture image

The image for the GUIContent.

System.String tooltip

The tooltip for the GUIContent.

Returns
UnityEngine.GUIContent

Temporary GUIContent instance.

TempContent(Texture, String)
Gets a temporary GUIContent with the specified image and tooltip.
public static GUIContent TempContent(Texture image, string tooltip = null)
Parameters
UnityEngine.Texture image

The image for the GUIContent.

System.String tooltip

The tooltip for the GUIContent.

Returns
UnityEngine.GUIContent

Temporary GUIContent instance.