NGUI: Next-Gen UI kit  3.7.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Macros
NGUIMath Class Reference

Helper class containing generic functions used throughout the UI library. More...

Static Public Member Functions

static float Lerp (float from, float to, float factor)
 Lerp function that doesn't clamp the 'factor' in 0-1 range. More...
 
static int ClampIndex (int val, int max)
 Clamp the specified integer to be between 0 and below 'max'. More...
 
static int RepeatIndex (int val, int max)
 Wrap the index using repeating logic, so that for example +1 past the end means index of '1'. More...
 
static float WrapAngle (float angle)
 Ensure that the angle is within -180 to 180 range. More...
 
static float Wrap01 (float val)
 In the shader, equivalent function would be 'fract' More...
 
static int HexToDecimal (char ch)
 Convert a hexadecimal character to its decimal value. More...
 
static char DecimalToHexChar (int num)
 Convert a single 0-15 value into its hex representation. It's coded because int.ToString(format) syntax doesn't seem to be supported by Unity's Flash. It just silently crashes. More...
 
static string DecimalToHex8 (int num)
 Convert a decimal value to its hex representation. More...
 
static string DecimalToHex24 (int num)
 Convert a decimal value to its hex representation. It's coded because num.ToString("X6") syntax doesn't seem to be supported by Unity's Flash. It just silently crashes. string.Format("{0,6:X}", num).Replace(' ', '0') doesn't work either. It returns the format string, not the formatted value. More...
 
static string DecimalToHex32 (int num)
 Convert a decimal value to its hex representation. It's coded because num.ToString("X6") syntax doesn't seem to be supported by Unity's Flash. It just silently crashes. string.Format("{0,6:X}", num).Replace(' ', '0') doesn't work either. It returns the format string, not the formatted value. More...
 
static int ColorToInt (Color c)
 Convert the specified color to RGBA32 integer format. More...
 
static Color IntToColor (int val)
 Convert the specified RGBA32 integer to Color. More...
 
static string IntToBinary (int val, int bits)
 Convert the specified integer to a human-readable string representing the binary value. Useful for debugging bytes. More...
 
static Color HexToColor (uint val)
 Convenience conversion function, allowing hex format (0xRrGgBbAa). More...
 
static Rect ConvertToTexCoords (Rect rect, int width, int height)
 Convert from top-left based pixel coordinates to bottom-left based UV coordinates. More...
 
static Rect ConvertToPixels (Rect rect, int width, int height, bool round)
 Convert from bottom-left based UV coordinates to top-left based pixel coordinates. More...
 
static Rect MakePixelPerfect (Rect rect)
 Round the pixel rectangle's dimensions. More...
 
static Rect MakePixelPerfect (Rect rect, int width, int height)
 Round the texture coordinate rectangle's dimensions. More...
 
static Vector2 ConstrainRect (Vector2 minRect, Vector2 maxRect, Vector2 minArea, Vector2 maxArea)
 Constrain 'rect' to be within 'area' as much as possible, returning the Vector2 offset necessary for this to happen. This function is useful when trying to restrict one area (window) to always be within another (viewport). More...
 
static Bounds CalculateAbsoluteWidgetBounds (Transform trans)
 Calculate the combined bounds of all widgets attached to the specified game object or its children (in world space). More...
 
static Bounds CalculateRelativeWidgetBounds (Transform trans)
 Calculate the combined bounds of all widgets attached to the specified game object or its children (in relative-to-object space). More...
 
static Bounds CalculateRelativeWidgetBounds (Transform trans, bool considerInactive)
 Calculate the combined bounds of all widgets attached to the specified game object or its children (in relative-to-object space). More...
 
static Bounds CalculateRelativeWidgetBounds (Transform relativeTo, Transform content)
 Calculate the combined bounds of all widgets attached to the specified game object or its children (in relative-to-object space). More...
 
static Bounds CalculateRelativeWidgetBounds (Transform relativeTo, Transform content, bool considerInactive)
 Calculate the combined bounds of all widgets attached to the specified game object or its children (in relative-to-object space). More...
 
static Vector3 SpringDampen (ref Vector3 velocity, float strength, float deltaTime)
 This code is not framerate-independent: More...
 
static Vector2 SpringDampen (ref Vector2 velocity, float strength, float deltaTime)
 Same as the Vector3 version, it's a framerate-independent Lerp. More...
 
static float SpringLerp (float strength, float deltaTime)
 Calculate how much to interpolate by. More...
 
static float SpringLerp (float from, float to, float strength, float deltaTime)
 Mathf.Lerp(from, to, Time.deltaTime * strength) is not framerate-independent. This function is. More...
 
static Vector2 SpringLerp (Vector2 from, Vector2 to, float strength, float deltaTime)
 Vector2.Lerp(from, to, Time.deltaTime * strength) is not framerate-independent. This function is. More...
 
static Vector3 SpringLerp (Vector3 from, Vector3 to, float strength, float deltaTime)
 Vector3.Lerp(from, to, Time.deltaTime * strength) is not framerate-independent. This function is. More...
 
static Quaternion SpringLerp (Quaternion from, Quaternion to, float strength, float deltaTime)
 Quaternion.Slerp(from, to, Time.deltaTime * strength) is not framerate-independent. This function is. More...
 
static float RotateTowards (float from, float to, float maxAngle)
 Since there is no Mathf.RotateTowards... More...
 
static float DistanceToRectangle (Vector2[] screenPoints, Vector2 mousePos)
 Determine the distance from the mouse position to the screen space rectangle specified by the 4 points. More...
 
static float DistanceToRectangle (Vector3[] worldPoints, Vector2 mousePos, Camera cam)
 Determine the distance from the mouse position to the world rectangle specified by the 4 points. More...
 
static Vector2 GetPivotOffset (UIWidget.Pivot pv)
 Helper function that converts the widget's pivot enum into a 0-1 range vector. More...
 
static UIWidget.Pivot GetPivot (Vector2 offset)
 Helper function that converts the pivot offset to a pivot point. More...
 
static void MoveWidget (UIRect w, float x, float y)
 Adjust the widget's position using the specified local delta coordinates. More...
 
static void MoveRect (UIRect rect, float x, float y)
 Adjust the rectangle's position using the specified local delta coordinates. More...
 
static void ResizeWidget (UIWidget w, UIWidget.Pivot pivot, float x, float y, int minWidth, int minHeight)
 Given the specified dragged pivot point, adjust the widget's dimensions. More...
 
static void ResizeWidget (UIWidget w, UIWidget.Pivot pivot, float x, float y, int minWidth, int minHeight, int maxWidth, int maxHeight)
 Given the specified dragged pivot point, adjust the widget's dimensions. More...
 
static void AdjustWidget (UIWidget w, float left, float bottom, float right, float top)
 Adjust the widget's rectangle based on the specified modifier values. More...
 
static void AdjustWidget (UIWidget w, float left, float bottom, float right, float top, int minWidth, int minHeight)
 Adjust the widget's rectangle based on the specified modifier values. More...
 
static void AdjustWidget (UIWidget w, float left, float bottom, float right, float top, int minWidth, int minHeight, int maxWidth, int maxHeight)
 Adjust the widget's rectangle based on the specified modifier values. More...
 
static int AdjustByDPI (float height)
 Adjust the specified value by DPI: height * 96 / DPI. This will result in in a smaller value returned for higher pixel density devices. More...
 
static Vector2 ScreenToPixels (Vector2 pos, Transform relativeTo)
 Convert the specified position, making it relative to the specified object. More...
 
static Vector2 ScreenToParentPixels (Vector2 pos, Transform relativeTo)
 Convert the specified position, making it relative to the specified object's parent. Useful if you plan on positioning the widget using the specified value (think mouse cursor). More...
 
static Vector3 WorldToLocalPoint (Vector3 worldPos, Camera worldCam, Camera uiCam, Transform relativeTo)
 Convert the specified world point from one camera's world space to another, then make it relative to the specified transform. You should use this function if you want to position a widget using some 3D point in space. Pass your main camera for the "worldCam", and your UI camera for "uiCam", then the widget's transform for "relativeTo". You can then assign the widget's localPosition to the returned value. More...
 
static void OverlayPosition (this Transform trans, Vector3 worldPos, Camera worldCam, Camera myCam)
 Helper function that can set the transform's position to be at the specified world position. Ideal usage: positioning a UI element to be directly over a 3D point in space. More...
 
static void OverlayPosition (this Transform trans, Vector3 worldPos, Camera worldCam)
 Helper function that can set the transform's position to be at the specified world position. Ideal usage: positioning a UI element to be directly over a 3D point in space. More...
 
static void OverlayPosition (this Transform trans, Transform target)
 Helper function that can set the transform's position to be over the specified target transform. Ideal usage: positioning a UI element to be directly over a 3D object in space. More...
 

Detailed Description

Helper class containing generic functions used throughout the UI library.

Member Function Documentation

static int NGUIMath.AdjustByDPI ( float  height)
static

Adjust the specified value by DPI: height * 96 / DPI. This will result in in a smaller value returned for higher pixel density devices.

static void NGUIMath.AdjustWidget ( UIWidget  w,
float  left,
float  bottom,
float  right,
float  top 
)
static

Adjust the widget's rectangle based on the specified modifier values.

static void NGUIMath.AdjustWidget ( UIWidget  w,
float  left,
float  bottom,
float  right,
float  top,
int  minWidth,
int  minHeight 
)
static

Adjust the widget's rectangle based on the specified modifier values.

static void NGUIMath.AdjustWidget ( UIWidget  w,
float  left,
float  bottom,
float  right,
float  top,
int  minWidth,
int  minHeight,
int  maxWidth,
int  maxHeight 
)
static

Adjust the widget's rectangle based on the specified modifier values.

static Bounds NGUIMath.CalculateAbsoluteWidgetBounds ( Transform  trans)
static

Calculate the combined bounds of all widgets attached to the specified game object or its children (in world space).

static Bounds NGUIMath.CalculateRelativeWidgetBounds ( Transform  trans)
static

Calculate the combined bounds of all widgets attached to the specified game object or its children (in relative-to-object space).

static Bounds NGUIMath.CalculateRelativeWidgetBounds ( Transform  trans,
bool  considerInactive 
)
static

Calculate the combined bounds of all widgets attached to the specified game object or its children (in relative-to-object space).

static Bounds NGUIMath.CalculateRelativeWidgetBounds ( Transform  relativeTo,
Transform  content 
)
static

Calculate the combined bounds of all widgets attached to the specified game object or its children (in relative-to-object space).

static Bounds NGUIMath.CalculateRelativeWidgetBounds ( Transform  relativeTo,
Transform  content,
bool  considerInactive 
)
static

Calculate the combined bounds of all widgets attached to the specified game object or its children (in relative-to-object space).

static int NGUIMath.ClampIndex ( int  val,
int  max 
)
static

Clamp the specified integer to be between 0 and below 'max'.

static int NGUIMath.ColorToInt ( Color  c)
static

Convert the specified color to RGBA32 integer format.

static Vector2 NGUIMath.ConstrainRect ( Vector2  minRect,
Vector2  maxRect,
Vector2  minArea,
Vector2  maxArea 
)
static

Constrain 'rect' to be within 'area' as much as possible, returning the Vector2 offset necessary for this to happen. This function is useful when trying to restrict one area (window) to always be within another (viewport).

static Rect NGUIMath.ConvertToPixels ( Rect  rect,
int  width,
int  height,
bool  round 
)
static

Convert from bottom-left based UV coordinates to top-left based pixel coordinates.

static Rect NGUIMath.ConvertToTexCoords ( Rect  rect,
int  width,
int  height 
)
static

Convert from top-left based pixel coordinates to bottom-left based UV coordinates.

static string NGUIMath.DecimalToHex24 ( int  num)
static

Convert a decimal value to its hex representation. It's coded because num.ToString("X6") syntax doesn't seem to be supported by Unity's Flash. It just silently crashes. string.Format("{0,6:X}", num).Replace(' ', '0') doesn't work either. It returns the format string, not the formatted value.

static string NGUIMath.DecimalToHex32 ( int  num)
static

Convert a decimal value to its hex representation. It's coded because num.ToString("X6") syntax doesn't seem to be supported by Unity's Flash. It just silently crashes. string.Format("{0,6:X}", num).Replace(' ', '0') doesn't work either. It returns the format string, not the formatted value.

static string NGUIMath.DecimalToHex8 ( int  num)
static

Convert a decimal value to its hex representation.

static char NGUIMath.DecimalToHexChar ( int  num)
static

Convert a single 0-15 value into its hex representation. It's coded because int.ToString(format) syntax doesn't seem to be supported by Unity's Flash. It just silently crashes.

static float NGUIMath.DistanceToRectangle ( Vector2[]  screenPoints,
Vector2  mousePos 
)
static

Determine the distance from the mouse position to the screen space rectangle specified by the 4 points.

static float NGUIMath.DistanceToRectangle ( Vector3[]  worldPoints,
Vector2  mousePos,
Camera  cam 
)
static

Determine the distance from the mouse position to the world rectangle specified by the 4 points.

static UIWidget.Pivot NGUIMath.GetPivot ( Vector2  offset)
static

Helper function that converts the pivot offset to a pivot point.

static Vector2 NGUIMath.GetPivotOffset ( UIWidget.Pivot  pv)
static

Helper function that converts the widget's pivot enum into a 0-1 range vector.

static Color NGUIMath.HexToColor ( uint  val)
static

Convenience conversion function, allowing hex format (0xRrGgBbAa).

static int NGUIMath.HexToDecimal ( char  ch)
static

Convert a hexadecimal character to its decimal value.

static string NGUIMath.IntToBinary ( int  val,
int  bits 
)
static

Convert the specified integer to a human-readable string representing the binary value. Useful for debugging bytes.

static Color NGUIMath.IntToColor ( int  val)
static

Convert the specified RGBA32 integer to Color.

static float NGUIMath.Lerp ( float  from,
float  to,
float  factor 
)
static

Lerp function that doesn't clamp the 'factor' in 0-1 range.

static Rect NGUIMath.MakePixelPerfect ( Rect  rect)
static

Round the pixel rectangle's dimensions.

static Rect NGUIMath.MakePixelPerfect ( Rect  rect,
int  width,
int  height 
)
static

Round the texture coordinate rectangle's dimensions.

static void NGUIMath.MoveRect ( UIRect  rect,
float  x,
float  y 
)
static

Adjust the rectangle's position using the specified local delta coordinates.

static void NGUIMath.MoveWidget ( UIRect  w,
float  x,
float  y 
)
static

Adjust the widget's position using the specified local delta coordinates.

static void NGUIMath.OverlayPosition ( this Transform  trans,
Vector3  worldPos,
Camera  worldCam,
Camera  myCam 
)
static

Helper function that can set the transform's position to be at the specified world position. Ideal usage: positioning a UI element to be directly over a 3D point in space.

Parameters
worldPosWorld position, visible by the worldCam
worldCamCamera that is able to see the worldPos
myCamCamera that is able to see the transform this function is called on
static void NGUIMath.OverlayPosition ( this Transform  trans,
Vector3  worldPos,
Camera  worldCam 
)
static

Helper function that can set the transform's position to be at the specified world position. Ideal usage: positioning a UI element to be directly over a 3D point in space.

Parameters
worldPosWorld position, visible by the worldCam
worldCamCamera that is able to see the worldPos
static void NGUIMath.OverlayPosition ( this Transform  trans,
Transform  target 
)
static

Helper function that can set the transform's position to be over the specified target transform. Ideal usage: positioning a UI element to be directly over a 3D object in space.

Parameters
targetTarget over which the transform should be positioned
static int NGUIMath.RepeatIndex ( int  val,
int  max 
)
static

Wrap the index using repeating logic, so that for example +1 past the end means index of '1'.

static void NGUIMath.ResizeWidget ( UIWidget  w,
UIWidget.Pivot  pivot,
float  x,
float  y,
int  minWidth,
int  minHeight 
)
static

Given the specified dragged pivot point, adjust the widget's dimensions.

static void NGUIMath.ResizeWidget ( UIWidget  w,
UIWidget.Pivot  pivot,
float  x,
float  y,
int  minWidth,
int  minHeight,
int  maxWidth,
int  maxHeight 
)
static

Given the specified dragged pivot point, adjust the widget's dimensions.

static float NGUIMath.RotateTowards ( float  from,
float  to,
float  maxAngle 
)
static

Since there is no Mathf.RotateTowards...

static Vector2 NGUIMath.ScreenToParentPixels ( Vector2  pos,
Transform  relativeTo 
)
static

Convert the specified position, making it relative to the specified object's parent. Useful if you plan on positioning the widget using the specified value (think mouse cursor).

static Vector2 NGUIMath.ScreenToPixels ( Vector2  pos,
Transform  relativeTo 
)
static

Convert the specified position, making it relative to the specified object.

static Vector3 NGUIMath.SpringDampen ( ref Vector3  velocity,
float  strength,
float  deltaTime 
)
static

This code is not framerate-independent:

target.position += velocity; velocity = Vector3.Lerp(velocity, Vector3.zero, Time.deltaTime * 9f);

But this code is:

target.position += NGUIMath.SpringDampen(ref velocity, 9f, Time.deltaTime);

static Vector2 NGUIMath.SpringDampen ( ref Vector2  velocity,
float  strength,
float  deltaTime 
)
static

Same as the Vector3 version, it's a framerate-independent Lerp.

static float NGUIMath.SpringLerp ( float  strength,
float  deltaTime 
)
static

Calculate how much to interpolate by.

static float NGUIMath.SpringLerp ( float  from,
float  to,
float  strength,
float  deltaTime 
)
static

Mathf.Lerp(from, to, Time.deltaTime * strength) is not framerate-independent. This function is.

static Vector2 NGUIMath.SpringLerp ( Vector2  from,
Vector2  to,
float  strength,
float  deltaTime 
)
static

Vector2.Lerp(from, to, Time.deltaTime * strength) is not framerate-independent. This function is.

static Vector3 NGUIMath.SpringLerp ( Vector3  from,
Vector3  to,
float  strength,
float  deltaTime 
)
static

Vector3.Lerp(from, to, Time.deltaTime * strength) is not framerate-independent. This function is.

static Quaternion NGUIMath.SpringLerp ( Quaternion  from,
Quaternion  to,
float  strength,
float  deltaTime 
)
static

Quaternion.Slerp(from, to, Time.deltaTime * strength) is not framerate-independent. This function is.

static Vector3 NGUIMath.WorldToLocalPoint ( Vector3  worldPos,
Camera  worldCam,
Camera  uiCam,
Transform  relativeTo 
)
static

Convert the specified world point from one camera's world space to another, then make it relative to the specified transform. You should use this function if you want to position a widget using some 3D point in space. Pass your main camera for the "worldCam", and your UI camera for "uiCam", then the widget's transform for "relativeTo". You can then assign the widget's localPosition to the returned value.

static float NGUIMath.Wrap01 ( float  val)
static

In the shader, equivalent function would be 'fract'

static float NGUIMath.WrapAngle ( float  angle)
static

Ensure that the angle is within -180 to 180 range.


The documentation for this class was generated from the following file: