Version 3.3.0.1

GUIHelper class

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

Fields

RepaintRequested
Gets a value indicating whether a repaint has been requested.
public static bool RepaintRequested

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. Setting this has been removed. Use PushContextWidth and PopContextWidth instead.
public static float ContextWidth { get; }
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; }

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(Int32).
public static void BeginLayoutMeasuring()
BeginLayoutMeasuring(out Int32)
Begins the layout measuring. Remember to end with EndLayoutMeasuring(Int32).
public static void BeginLayoutMeasuring(out int cursor)
Parameters
System.Int32 cursor

CalcHeight(GUIStyle, String, Single)
Measures the height of a given System.String, if it would be presented with this UnityEngine.GUIStyle.
public static float CalcHeight(this GUIStyle style, string text, float width)
Parameters
UnityEngine.GUIStyle style

The UnityEngine.GUIStyle to present the System.String as.

System.String text

The System.String to measure.

System.Single width

The width of the area the System.String is being presented in.

Returns
System.Single

The height of the System.String.

CalcMinMaxWidth(GUIStyle, String, out Single, out Single)
Measures the min- & max width of a given System.String, if it would be presented with this UnityEngine.GUIStyle.
public static void CalcMinMaxWidth(this GUIStyle style, string text, out float minWidth, out float maxWidth)
Parameters
UnityEngine.GUIStyle style

The UnityEngine.GUIStyle to present the System.String as.

System.String text

The System.String to measure.

System.Single minWidth

The minimum width of the System.String.

System.Single maxWidth

The maximum width of the System.String.

CalcSize(GUIStyle, String)
Measures the size of a given System.String, if it would be presented with this UnityEngine.GUIStyle.
public static Vector2 CalcSize(this GUIStyle style, string text)
Parameters
UnityEngine.GUIStyle style

The UnityEngine.GUIStyle to present the System.String as.

System.String text

The System.String to measure.

Returns
UnityEngine.Vector2

A UnityEngine.Vector2 consisting of the width (UnityEngine.Vector2.x) & height (UnityEngine.Vector2.y), as the size of the System.String in GUI-space.

CalcWidth(GUIStyle, String)
Measures the width of a given System.String, if it would be presented with this UnityEngine.GUIStyle.
public static float CalcWidth(this GUIStyle style, string text)
Parameters
UnityEngine.GUIStyle style

The UnityEngine.GUIStyle to present the System.String as.

System.String text

The System.String to measure.

Returns
System.Single

The width of the System.String.

CalcWidth(GUIStyle, GUIContent)
Measures the width of a given UnityEngine.GUIContent, if it would be presented with this UnityEngine.GUIStyle.
public static float CalcWidth(this GUIStyle style, GUIContent content)
Parameters
UnityEngine.GUIStyle style

The UnityEngine.GUIStyle to present the UnityEngine.GUIContent as.

UnityEngine.GUIContent content

The UnityEngine.GUIContent to measure.

Returns
System.Single

The width of the UnityEngine.GUIContent.

ClearRepaintRequest()
Clears the repaint request.
public static void ClearRepaintRequest()
DisplaySmartUpdatingCancellableProgressBar(String, String, Single, Int32)
public static bool DisplaySmartUpdatingCancellableProgressBar(string title, string details, float progress, int updateIntervalByMS = 150)
Parameters
System.String title

System.String details

System.Single progress

System.Int32 updateIntervalByMS

Returns
System.Boolean

DisplaySmartUpdatingCancellableProgressBar(String, String, Single, Int32, Int32)
public static bool DisplaySmartUpdatingCancellableProgressBar(string title, string details, float progress, int updateIntervalByMS, 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

DrawLastControlId(String, Int32)
public static void DrawLastControlId(string name = null, int lineNumber = 0)
Parameters
System.String name

System.Int32 lineNumber

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 EndLayoutMeasuring(Int32)
public static Rect EndLayoutMeasuring()
Returns
UnityEngine.Rect

The measured rect.

EndLayoutMeasuring(Int32)
Ends the layout measuring started by EndLayoutMeasuring(Int32)
public static Rect EndLayoutMeasuring(int cursor)
Parameters
System.Int32 cursor

Returns
UnityEngine.Rect

The measured rect.

ExitGUI(Boolean)
public static void ExitGUI(bool removeFocusControl)
Parameters
System.Boolean removeFocusControl

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.

GetPreviewTexture(Object)
Gets a preview texture for the provided object.
public static Texture GetPreviewTexture(Object objectToPreview)
Parameters
UnityEngine.Object objectToPreview

Returns
UnityEngine.Texture

Exceptions
System.ArgumentNullException

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()
PopContextWidth()
Pops a value pushed by PushContextWidth(Single).
public static void PopContextWidth()
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.

PushContextWidth(Single)
Pushes a context width to the context width stack. Remember to pop the value again with PopContextWidth().
public static void PushContextWidth(float width)
Parameters
System.Single width

The width to push.

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()
SelectObject(Object)
public static void SelectObject(Object obj)
Parameters
UnityEngine.Object obj

ShouldDisplaySmartCancellableProgressBar(Int32)
public static bool ShouldDisplaySmartCancellableProgressBar(int updateIntervalByMS = 150)
Parameters
System.Int32 updateIntervalByMS

Returns
System.Boolean

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.