Wanzyee Studio
AidGUI

Implement some runtime GUI layout and functional aid methods. More...

Static Public Member Functions

static bool CheckFocus (int id=0, params KeyCode[] keys)
 Check if currently focus on a text field, and unfocus if click outside or press ESC key. More...
 
static void PrefixLabel (GUIContent label)
 Draw prefix label without width expanding nor line breaking. More...
 
static string TextArea (GUIContent label, string text, params GUILayoutOption[] options)
 Draw multiline text field with prefix label. More...
 
static bool Toggle (GUIContent label, bool value, params GUILayoutOption[] options)
 Draw bool toggle with prefix label, and the value string behind. More...
 
static int IntField (GUIContent label, int value, int min=0, int max=0, params GUILayoutOption[] options)
 Draw int field with limited slider, or shuttle if limitations are the same. More...
 
static float FloatField (GUIContent label, float value, float min=0f, float max=0f, params GUILayoutOption[] options)
 Draw float field with limited slider, or shuttle if limitations are the same. More...
 
static void MultiIntField (GUIContent label, GUIContent[] subLabels, int[] values, params GUILayoutOption[] options)
 Draw multiple IntField() in one line with paired sub labels and values. More...
 
static void MultiFloatField (GUIContent label, GUIContent[] subLabels, float[] values, params GUILayoutOption[] options)
 Draw multiple FloatField() in one line with paired sub labels and values. More...
 
static Vector2 Vector2Field (GUIContent label, Vector2 value, params GUILayoutOption[] options)
 Draw UnityEngine.Vector2 field with 2 FloatField() in one line. More...
 
static Vector3 Vector3Field (GUIContent label, Vector3 value, params GUILayoutOption[] options)
 Draw UnityEngine.Vector3 field with 3 FloatField() in one line. More...
 
static Vector4 Vector4Field (GUIContent label, Vector4 value, params GUILayoutOption[] options)
 Draw UnityEngine.Vector4 field with 4 FloatField() in one line. More...
 
static Quaternion QuaternionField (GUIContent label, Quaternion value, params GUILayoutOption[] options)
 Draw UnityEngine.Quaternion field with 4 FloatField() in one line. More...
 
static Rect RectField (GUIContent label, Rect value, params GUILayoutOption[] options)
 Draw UnityEngine.Rect field with 4 FloatField() in one line. More...
 
static RectOffset RectOffsetField (GUIContent label, RectOffset value, params GUILayoutOption[] options)
 Draw UnityEngine.RectOffset field with 4 IntField() in one line. More...
 
static Bounds BoundsField (GUIContent label, Bounds value, params GUILayoutOption[] options)
 Draw UnityEngine.Bounds field with 2 lines of Vector3Field(). More...
 
static Matrix4x4 Matrix4x4Field (GUIContent label, Matrix4x4 value, params GUILayoutOption[] options)
 Draw UnityEngine.Matrix4x4 field in 4 lines, each has 4 FloatField(). More...
 
static Color ColorField (GUIContent label, Color value, params GUILayoutOption[] options)
 Draw UnityEngine.Color field with preview and 4 sliders to tweak RGBA or HSVA. More...
 
static T EnumRadio< T > (GUIContent label, T value, params GUILayoutOption[] options)
 Draw radio toggles to select enum. More...
 
static T EnumMaskRadio< T > (GUIContent label, T value, params GUILayoutOption[] options)
 Draw radio toggles to multi select mask enum. More...
 
static T ValueField< T > (GUIContent label, T value, params GUILayoutOption[] options)
 Draw the value field formatted by the value type. More...
 
static T TextField< T > (GUIContent label, T value, params GUILayoutOption[] options)
 Draw the text field to display JSON serialized value. More...
 
static Vector2 GUIToScreenPoint (Vector2 guiPoint)
 Convert a point from GUI position to screen space. More...
 
static Vector2 ScreenToGUIPoint (Vector2 screenPoint)
 Convert a point from screen space to GUI position. More...
 
static void DrawLine (Vector2 start, Vector2 end, Color color=default, float width=2f)
 Draw a line from the start point to the end, with specified color and line width. More...
 
static void DrawPolygon (Color color, float width, bool close, params Vector2[] points)
 Draw a polygon connects all points with color and line width, optional to close it. More...
 
static void DrawPolygon (bool close, params Vector2[] points)
 Draw a polygon connects all points, optional to close it. More...
 
static void DrawBorder (Rect rect, Color color=default, float width=2f)
 Draw a border, empty rect with 4 lines. More...
 

Detailed Description

Implement some runtime GUI layout and functional aid methods.

Member Function Documentation

static bool CheckFocus ( int  id = 0,
params KeyCode[]  keys 
)
static

Check if currently focus on a text field, and unfocus if click outside or press ESC key.

Optional to assign extra keys to unfocus besides escape key. If specify control ID, check extra keys only if focus on it now, and return if still focused. Otherwise, check extra keys whenever key down, and return if any text control focused.

Parameters
idControl ID.
keysKeys to unfocus when press.
Returns
true, if focused, false otherwise.
static void PrefixLabel ( GUIContent  label)
static

Draw prefix label without width expanding nor line breaking.

Parameters
labelLabel.
static string TextArea ( GUIContent  label,
string  text,
params GUILayoutOption[]  options 
)
static

Draw multiline text field with prefix label.

Unfocus if click outside or press escape key. This applies options to horizontal group, may cause 4px more than normal above and below.

Parameters
labelLabel.
textText value.
optionsLayout options.
Returns
The new value.
static bool Toggle ( GUIContent  label,
bool  value,
params GUILayoutOption[]  options 
)
static

Draw bool toggle with prefix label, and the value string behind.

This applies options to horizontal group, may cause 4px more than normal above and below.

Parameters
labelLabel.
valueValue.
optionsLayout options.
Returns
The new value.
static int IntField ( GUIContent  label,
int  value,
int  min = 0,
int  max = 0,
params GUILayoutOption[]  options 
)
static

Draw int field with limited slider, or shuttle if limitations are the same.

This applies options to horizontal group, may cause 4px more than normal above and below.

Parameters
labelLabel.
valueValue.
minMin value to clamp.
maxMax value to clamp.
optionsLayout options.
Returns
The new value.
static float FloatField ( GUIContent  label,
float  value,
float  min = 0f,
float  max = 0f,
params GUILayoutOption[]  options 
)
static

Draw float field with limited slider, or shuttle if limitations are the same.

This applies options to horizontal group, may cause 4px more than normal above and below.

Parameters
labelLabel.
valueValue.
minMin value to clamp.
maxMax value to clamp.
optionsLayout options.
Returns
The new value.
static void MultiIntField ( GUIContent  label,
GUIContent[]  subLabels,
int[]  values,
params GUILayoutOption[]  options 
)
static

Draw multiple IntField() in one line with paired sub labels and values.

The edited results will be set back to the values array. This applies options to horizontal group, may cause 4px more than normal above and below.

Parameters
labelMain label.
subLabelsSub labels.
valuesValues array.
optionsLayout options.
static void MultiFloatField ( GUIContent  label,
GUIContent[]  subLabels,
float[]  values,
params GUILayoutOption[]  options 
)
static

Draw multiple FloatField() in one line with paired sub labels and values.

The edited results will be set back to the values array. This applies options to horizontal group, may cause 4px more than normal above and below.

Parameters
labelMain label.
subLabelsSub labels.
valuesValues array.
optionsLayout options.
static Vector2 Vector2Field ( GUIContent  label,
Vector2  value,
params GUILayoutOption[]  options 
)
static

Draw UnityEngine.Vector2 field with 2 FloatField() in one line.

This applies options to horizontal group, may cause 4px more than normal above and below.

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

Draw UnityEngine.Vector3 field with 3 FloatField() in one line.

This applies options to horizontal group, may cause 4px more than normal above and below.

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

Draw UnityEngine.Vector4 field with 4 FloatField() in one line.

This applies options to horizontal group, may cause 4px more than normal above and below.

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

Draw UnityEngine.Quaternion field with 4 FloatField() in one line.

This applies options to horizontal group, may cause 4px more than normal above and below.

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

Draw UnityEngine.Rect field with 4 FloatField() in one line.

This applies options to horizontal group, may cause 4px more than normal above and below.

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

Draw UnityEngine.RectOffset field with 4 IntField() in one line.

This will return new instance although it's class. This applies options to horizontal group, may cause 4px more than normal above and below.

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

Draw UnityEngine.Bounds field with 2 lines of Vector3Field().

This applies options to horizontal group, may cause 4px more than normal above and below.

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

Draw UnityEngine.Matrix4x4 field in 4 lines, each has 4 FloatField().

This applies options to horizontal group, may cause 4px more than normal above and below.

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

Draw UnityEngine.Color field with preview and 4 sliders to tweak RGBA or HSVA.

Click preview field to switch color mode. This applies options to horizontal group, may cause 4px more than normal above and below.

Parameters
labelLabel.
valueValue.
optionsLayout options.
Returns
The new value.
static T EnumRadio< T > ( GUIContent  label,
value,
params GUILayoutOption[]  options 
)
static

Draw radio toggles to select enum.

This applies options to horizontal group, may cause 4px more than normal above and below.

Template Parameters
TThe enum type.
Parameters
labelLabel.
valueValue.
optionsLayout options.
Returns
The new value.
static T EnumMaskRadio< T > ( GUIContent  label,
value,
params GUILayoutOption[]  options 
)
static

Draw radio toggles to multi select mask enum.

This applies options to horizontal group, may cause 4px more than normal above and below.

Template Parameters
TThe enum type.
Parameters
labelLabel.
valueValue.
optionsLayout options.
Returns
The new value.
static T ValueField< T > ( GUIContent  label,
value,
params GUILayoutOption[]  options 
)
static

Draw the value field formatted by the value type.

If it is an array and the length is changed on GUI, this will return a new instance. Note, unassigned T becomes object if pass value null.

It's able to make a custom layout for a custom type, instead of default as a text field. Just make a class implements IAidDrawer, this'll find it to draw the GUI. Note, this instantiates the custom drawer by the default constructor. E.g., the classes below aren't allowed to implement:

  1. UnityEngine.MonoBehaviour.
  2. UnityEngine.ScriptableObject.
Template Parameters
TThe value type.
Parameters
labelLabel.
valueValue.
optionsLayout options.
Returns
The new value.
static T TextField< T > ( GUIContent  label,
value,
params GUILayoutOption[]  options 
)
static

Draw the text field to display JSON serialized value.

Use temporary content if focused, highlight if different from the original. Unfocus if click outside, press escape or enter key. Note, this will return new deserialized value instance if changed, otherwise original. This applies options to horizontal group, may cause 4px more than normal above and below.

Template Parameters
TThe value type.
Parameters
labelLabel.
valueValue.
optionsLayout options.
Returns
The new value.
static Vector2 GUIToScreenPoint ( Vector2  guiPoint)
static

Convert a point from GUI position to screen space.

Parameters
guiPointGUI point.
Returns
The screen point.
static Vector2 ScreenToGUIPoint ( Vector2  screenPoint)
static

Convert a point from screen space to GUI position.

The result is the same as Event.mousePosition if assigning Input.mousePosition.

Parameters
screenPointScreen point.
Returns
The GUI point.
static void DrawLine ( Vector2  start,
Vector2  end,
Color  color = default,
float  width = 2f 
)
static

Draw a line from the start point to the end, with specified color and line width.

Parameters
startStart point.
endEnd point.
colorLine color.
widthLine width.
static void DrawPolygon ( Color  color,
float  width,
bool  close,
params Vector2[]  points 
)
static

Draw a polygon connects all points with color and line width, optional to close it.

Parameters
colorLine color.
widthLine width.
closeIf set to true close.
pointsPoints.
static void DrawPolygon ( bool  close,
params Vector2[]  points 
)
static

Draw a polygon connects all points, optional to close it.

Parameters
closeIf set to true close.
pointsPoints.
static void DrawBorder ( Rect  rect,
Color  color = default,
float  width = 2f 
)
static

Draw a border, empty rect with 4 lines.

Parameters
rectRect.
colorLine color.
widthLine width.