Wanzyee Studio

Include some convenient methods for editor GUI. More...

Static Public Member Functions

static float GetLabelWidth (float viewWidth=0f)
 Get the label width within the specified view width. More...
 
static void SetIconForObject (Object obj, Texture2D icon)
 Set the icon for the specified UnityEngine.Object to show in the Inspector or Project window. More...
 
static void MultiFloatField (GUIContent label, GUIContent[] subLabels, float[] values, params GUILayoutOption[] options)
 Make a multi-control with text fields for entering multiple floats in the same line. More...
 
static Vector4 Vector4Field (GUIContent label, Vector4 value, params GUILayoutOption[] options)
 Make an X, Y, Z and W field for entering a UnityEngine.Vector4. More...
 
static Quaternion QuaternionField (GUIContent label, Quaternion value, params GUILayoutOption[] options)
 Make an X, Y, Z and W field for entering a UnityEngine.Quaternion. More...
 
static string SearchField (string text, Action onPopup=null, params GUILayoutOption[] options)
 Make a toolbar style search field, optional to set a callback invoked when click the magnifier popup icon. More...
 
static void ErrorField (Rect rect, GUIContent label, GUIContent error)
 Display an error message after the prefix label. More...
 
static void NamelessField (Rect rect, SerializedProperty property, string path="", bool border=false)
 Make a simple property field without the label, but still tooltip if exists. More...
 
static int CheckClick (Rect rect, int button=0, bool ctrl=false, bool shift=false, bool alt=false)
 Check if click in the specified rect, optional to combine the modifier keys. More...
 
static bool StartDragObjects (Rect rect, params Object[] sources)
 Try to start Drag'n'Drop the specified objects. More...
 
static bool StartDragObjects (Rect rect, Func< IEnumerable< Object >> sourcer)
 Try to start Drag'n'Drop the specified objects. More...
 
static bool StartDragPaths (Rect rect, params string[] sources)
 Try to start Drag'n'Drop the specified paths. More...
 
static bool StartDragPaths (Rect rect, Func< IEnumerable< string >> sourcer)
 Try to start Drag'n'Drop the specified paths. More...
 
static Object[] AcceptDragObjects (Rect rect, Func< Object, bool > filter)
 Try to accept Drag'n'Drop with the filtered dragged objects. More...
 
static Object[] AcceptDragObjects (Rect rect, Func< IEnumerable< Object >, IEnumerable< Object >> filter=null)
 Try to accept Drag'n'Drop with the filtered dragged objects. More...
 
static string[] AcceptDragPaths (Rect rect, Func< string, bool > filter)
 Try to accept Drag'n'Drop with the filtered dragged paths. More...
 
static string[] AcceptDragPaths (Rect rect, Func< IEnumerable< string >, IEnumerable< string >> filter=null)
 Try to accept Drag'n'Drop with the filtered dragged paths. More...
 

Detailed Description

Include some convenient methods for editor GUI.

3

Member Function Documentation

static float GetLabelWidth ( float  viewWidth = 0f)
static

Get the label width within the specified view width.

Commonly used for a prefix label in a resizable window. Use EditorGUIUtility.currentViewWidth instead if not assign.

Parameters
viewWidthView width.
Returns
The label width.
static void SetIconForObject ( Object  obj,
Texture2D  icon 
)
static

Set the icon for the specified UnityEngine.Object to show in the Inspector or Project window.

This wraps the internal EditorGUIUtility.SetIconForObject():

  1. It applies to all the same type objects, also the UnityEditor.MonoScript declares the type.
  2. You may pass the script asset to set without any object instance.
  3. To restore to default, pass a null icon.

The opposite methods below to get the icon:

  1. AssetPreview.GetMiniThumbnail() to get by UnityEngine.Object.
  2. AssetPreview.GetMiniTypeThumbnail() to get by System.Type.
  3. EditorGUIUtility.ObjectContent() to get by both.
Parameters
objObject.
iconIcon.
static void MultiFloatField ( GUIContent  label,
GUIContent[]  subLabels,
float[]  values,
params GUILayoutOption[]  options 
)
static

Make a multi-control with text fields for entering multiple floats in the same line.

Wrap EditorGUI.MultiFloatField() as the GUI layout automatically.

Parameters
labelMain label.
subLabelsSub labels.
valuesValues.
optionsLayout options.
static Vector4 Vector4Field ( GUIContent  label,
Vector4  value,
params GUILayoutOption[]  options 
)
static

Make an X, Y, Z and W field for entering a UnityEngine.Vector4.

Copycat of EditorGUILayout.Vector4Field() but use MultiFloatField(). Contrast to original, this correct line wrap and indent level.

Parameters
labelLabel.
valueValue.
optionsLayout options.
Returns
The new value.
static Quaternion QuaternionField ( GUIContent  label,
Quaternion  value,
params GUILayoutOption[]  options 
)
static

Make an X, Y, Z and W field for entering a UnityEngine.Quaternion.

Just looks like Vector4Field().

Parameters
labelLabel.
valueValue.
optionsLayout options.
Returns
The new value.
static string SearchField ( string  text,
Action  onPopup = null,
params GUILayoutOption[]  options 
)
static

Make a toolbar style search field, optional to set a callback invoked when click the magnifier popup icon.

Parameters
textThe text to edit.
onPopupThe popup callback.
optionsLayout options.
Returns
The new text.
static void ErrorField ( Rect  rect,
GUIContent  label,
GUIContent  error 
)
static

Display an error message after the prefix label.

Parameters
rectRect.
labelLabel.
errorError message.
static void NamelessField ( Rect  rect,
SerializedProperty  property,
string  path = "",
bool  border = false 
)
static

Make a simple property field without the label, but still tooltip if exists.

Parameters
rectRect.
propertyProperty.
pathRelative property path.
borderBackground border.
static int CheckClick ( Rect  rect,
int  button = 0,
bool  ctrl = false,
bool  shift = false,
bool  alt = false 
)
static

Check if click in the specified rect, optional to combine the modifier keys.

Parameters
rectRect of the click area.
buttonThe mouse button, 0 for left, 1 right and 2 middle button.
ctrlCombine modifier "Ctrl" or "Cmd".
shiftCombine modifier "Shift".
altCombine modifier "Alt".
Returns
The count of clicks.
static bool StartDragObjects ( Rect  rect,
params Object[]  sources 
)
static

Try to start Drag'n'Drop the specified objects.

Parameters
rectRect.
sourcesSources.
Returns
true if drag started.
static bool StartDragObjects ( Rect  rect,
Func< IEnumerable< Object >>  sourcer 
)
static

Try to start Drag'n'Drop the specified objects.

Parameters
rectRect.
sourcerCallback to get sources, invoked only when mouse down or drag.
Returns
true if drag started.
static bool StartDragPaths ( Rect  rect,
params string[]  sources 
)
static

Try to start Drag'n'Drop the specified paths.

Parameters
rectRect.
sourcesSources.
Returns
true if drag started.
static bool StartDragPaths ( Rect  rect,
Func< IEnumerable< string >>  sourcer 
)
static

Try to start Drag'n'Drop the specified paths.

Parameters
rectRect.
sourcerCallback to get sources, invoked only when mouse down or drag.
Returns
true if drag started.
static Object [] AcceptDragObjects ( Rect  rect,
Func< Object, bool >  filter 
)
static

Try to accept Drag'n'Drop with the filtered dragged objects.

Parameters
rectRect.
filterCallback to filter each object, invoked only when drag updated.
Returns
The filtered objects, only valid when drag performed, otherwise null.
static Object [] AcceptDragObjects ( Rect  rect,
Func< IEnumerable< Object >, IEnumerable< Object >>  filter = null 
)
static

Try to accept Drag'n'Drop with the filtered dragged objects.

Parameters
rectRect.
filterCallback to filter all objects, invoked only when drag updated.
Returns
The filtered objects, only valid when drag performed, otherwise null.
static string [] AcceptDragPaths ( Rect  rect,
Func< string, bool >  filter 
)
static

Try to accept Drag'n'Drop with the filtered dragged paths.

Parameters
rectRect.
filterCallback to filter each path, invoked only when drag updated.
Returns
The filtered paths, only valid when drag performed, otherwise null.
static string [] AcceptDragPaths ( Rect  rect,
Func< IEnumerable< string >, IEnumerable< string >>  filter = null 
)
static

Try to accept Drag'n'Drop with the filtered dragged paths.

Parameters
rectRect.
filterCallback to filter all paths, invoked only when drag updated.
Returns
The filtered paths, only valid when drag performed, otherwise null.