C# Class NGUIMath, TheUnseen

Helper class containing generic functions used throughout the UI library.
Exibir arquivo Open project: henryj41043/TheUnseen Class Usage Examples

Public Methods

Method Description
AdjustWidget ( UIWidget, w, float left, float bottom, float right, float top ) : void

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

AdjustWidget ( UIWidget, w, float left, float bottom, float right, float top, int minWidth, int minHeight ) : void

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

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

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

CalculateAbsoluteWidgetBounds ( Transform trans ) : Bounds

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

CalculateRelativeWidgetBounds ( Transform trans ) : Bounds

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

CalculateRelativeWidgetBounds ( Transform root, Transform child ) : Bounds

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

CalculateRelativeWidgetBounds ( Transform root, Transform child, bool considerInactive ) : Bounds

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

CalculateRelativeWidgetBounds ( Transform trans, bool considerInactive ) : Bounds

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

ConstrainRect ( Vector2 minRect, Vector2 maxRect, Vector2 minArea, Vector2 maxArea ) : Vector2

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).

ConvertToPixels ( Rect rect, int width, int height, bool round ) : Rect

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

ConvertToTexCoords ( Rect rect, int width, int height ) : Rect

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

DistanceToRectangle ( Vector2 screenPoints, Vector2 mousePos ) : float

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

DistanceToRectangle ( Vector3 worldPoints, Vector2 mousePos, Camera cam ) : float

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

GetPivot ( Vector2 offset ) : UIWidget.Pivot

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

GetPivotOffset ( UIWidget, pv ) : Vector2

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

MakePixelPerfect ( Rect rect ) : Rect

Round the pixel rectangle's dimensions.

MakePixelPerfect ( Rect rect, int width, int height ) : Rect

Round the texture coordinate rectangle's dimensions.

MoveRect ( UIRect, rect, float x, float y ) : void

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

MoveWidget ( UIRect, w, float x, float y ) : void

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

ResizeWidget ( UIWidget, w, UIWidget, pivot, float x, float y, int minWidth, int minHeight ) : void

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

ResizeWidget ( UIWidget, w, UIWidget, pivot, float x, float y, int minWidth, int minHeight, int maxWidth, int maxHeight ) : void

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

RotateTowards ( float from, float to, float maxAngle ) : float

Since there is no Mathf.RotateTowards...

SpringDampen ( Vector2 &velocity, float strength, float deltaTime ) : Vector2

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

SpringDampen ( Vector3 &velocity, float strength, float deltaTime ) : Vector3

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);

SpringLerp ( Quaternion from, Quaternion to, float strength, float deltaTime ) : Quaternion

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

SpringLerp ( Vector2 from, Vector2 to, float strength, float deltaTime ) : Vector2

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

SpringLerp ( Vector3 from, Vector3 to, float strength, float deltaTime ) : Vector3

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

SpringLerp ( float strength, float deltaTime ) : float

Calculate how much to interpolate by.

SpringLerp ( float from, float to, float strength, float deltaTime ) : float

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

Private Methods

Method Description
ClampIndex ( int val, int max ) : int
ColorToInt ( Color c ) : int
DecimalToHex ( int num ) : string
DecimalToHexChar ( int num ) : char
DistancePointToLineSegment ( Vector2 point, Vector2 a, Vector2 b ) : float

Determine the distance from the specified point to the line segment.

HexToColor ( uint val ) : Color
HexToDecimal ( char ch ) : int
IntToBinary ( int val, int bits ) : string
IntToColor ( int val ) : Color
Lerp ( float from, float to, float factor ) : float
RepeatIndex ( int val, int max ) : int
Wrap01 ( float val ) : float
WrapAngle ( float angle ) : float

Method Details

AdjustWidget() static public method

Adjust the widget's rectangle based on the specified modifier values.
static public AdjustWidget ( UIWidget, w, float left, float bottom, float right, float top ) : void
w UIWidget,
left float
bottom float
right float
top float
return void

AdjustWidget() static public method

Adjust the widget's rectangle based on the specified modifier values.
static public AdjustWidget ( UIWidget, w, float left, float bottom, float right, float top, int minWidth, int minHeight ) : void
w UIWidget,
left float
bottom float
right float
top float
minWidth int
minHeight int
return void

AdjustWidget() static public method

Adjust the widget's rectangle based on the specified modifier values.
static public AdjustWidget ( UIWidget, w, float left, float bottom, float right, float top, int minWidth, int minHeight, int maxWidth, int maxHeight ) : void
w UIWidget,
left float
bottom float
right float
top float
minWidth int
minHeight int
maxWidth int
maxHeight int
return void

CalculateAbsoluteWidgetBounds() static public method

Calculate the combined bounds of all widgets attached to the specified game object or its children (in world space).
static public CalculateAbsoluteWidgetBounds ( Transform trans ) : Bounds
trans Transform
return Bounds

CalculateRelativeWidgetBounds() static public method

Calculate the combined bounds of all widgets attached to the specified game object or its children (in relative-to-object space).
static public CalculateRelativeWidgetBounds ( Transform trans ) : Bounds
trans Transform
return Bounds

CalculateRelativeWidgetBounds() static public method

Calculate the combined bounds of all widgets attached to the specified game object or its children (in relative-to-object space).
static public CalculateRelativeWidgetBounds ( Transform root, Transform child ) : Bounds
root Transform
child Transform
return Bounds

CalculateRelativeWidgetBounds() static public method

Calculate the combined bounds of all widgets attached to the specified game object or its children (in relative-to-object space).
static public CalculateRelativeWidgetBounds ( Transform root, Transform child, bool considerInactive ) : Bounds
root Transform
child Transform
considerInactive bool
return Bounds

CalculateRelativeWidgetBounds() static public method

Calculate the combined bounds of all widgets attached to the specified game object or its children (in relative-to-object space).
static public CalculateRelativeWidgetBounds ( Transform trans, bool considerInactive ) : Bounds
trans Transform
considerInactive bool
return Bounds

ConstrainRect() static public method

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 public ConstrainRect ( Vector2 minRect, Vector2 maxRect, Vector2 minArea, Vector2 maxArea ) : Vector2
minRect Vector2
maxRect Vector2
minArea Vector2
maxArea Vector2
return Vector2

ConvertToPixels() static public method

Convert from bottom-left based UV coordinates to top-left based pixel coordinates.
static public ConvertToPixels ( Rect rect, int width, int height, bool round ) : Rect
rect Rect
width int
height int
round bool
return Rect

ConvertToTexCoords() static public method

Convert from top-left based pixel coordinates to bottom-left based UV coordinates.
static public ConvertToTexCoords ( Rect rect, int width, int height ) : Rect
rect Rect
width int
height int
return Rect

DistanceToRectangle() static public method

Determine the distance from the mouse position to the screen space rectangle specified by the 4 points.
static public DistanceToRectangle ( Vector2 screenPoints, Vector2 mousePos ) : float
screenPoints Vector2
mousePos Vector2
return float

DistanceToRectangle() static public method

Determine the distance from the mouse position to the world rectangle specified by the 4 points.
static public DistanceToRectangle ( Vector3 worldPoints, Vector2 mousePos, Camera cam ) : float
worldPoints Vector3
mousePos Vector2
cam Camera
return float

GetPivot() static public method

Helper function that converts the pivot offset to a pivot point.
static public GetPivot ( Vector2 offset ) : UIWidget.Pivot
offset Vector2
return UIWidget.Pivot

GetPivotOffset() static public method

Helper function that converts the widget's pivot enum into a 0-1 range vector.
static public GetPivotOffset ( UIWidget, pv ) : Vector2
pv UIWidget,
return Vector2

MakePixelPerfect() static public method

Round the pixel rectangle's dimensions.
static public MakePixelPerfect ( Rect rect ) : Rect
rect Rect
return Rect

MakePixelPerfect() static public method

Round the texture coordinate rectangle's dimensions.
static public MakePixelPerfect ( Rect rect, int width, int height ) : Rect
rect Rect
width int
height int
return Rect

MoveRect() static public method

Adjust the rectangle's position using the specified local delta coordinates.
static public MoveRect ( UIRect, rect, float x, float y ) : void
rect UIRect,
x float
y float
return void

MoveWidget() static public method

Adjust the widget's position using the specified local delta coordinates.
static public MoveWidget ( UIRect, w, float x, float y ) : void
w UIRect,
x float
y float
return void

ResizeWidget() static public method

Given the specified dragged pivot point, adjust the widget's dimensions.
static public ResizeWidget ( UIWidget, w, UIWidget, pivot, float x, float y, int minWidth, int minHeight ) : void
w UIWidget,
pivot UIWidget,
x float
y float
minWidth int
minHeight int
return void

ResizeWidget() static public method

Given the specified dragged pivot point, adjust the widget's dimensions.
static public ResizeWidget ( UIWidget, w, UIWidget, pivot, float x, float y, int minWidth, int minHeight, int maxWidth, int maxHeight ) : void
w UIWidget,
pivot UIWidget,
x float
y float
minWidth int
minHeight int
maxWidth int
maxHeight int
return void

RotateTowards() static public method

Since there is no Mathf.RotateTowards...
static public RotateTowards ( float from, float to, float maxAngle ) : float
from float
to float
maxAngle float
return float

SpringDampen() static public method

Same as the Vector3 version, it's a framerate-independent Lerp.
static public SpringDampen ( Vector2 &velocity, float strength, float deltaTime ) : Vector2
velocity Vector2
strength float
deltaTime float
return Vector2

SpringDampen() static public method

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 public SpringDampen ( Vector3 &velocity, float strength, float deltaTime ) : Vector3
velocity Vector3
strength float
deltaTime float
return Vector3

SpringLerp() static public method

Quaternion.Slerp(from, to, Time.deltaTime * strength) is not framerate-independent. This function is.
static public SpringLerp ( Quaternion from, Quaternion to, float strength, float deltaTime ) : Quaternion
from Quaternion
to Quaternion
strength float
deltaTime float
return Quaternion

SpringLerp() static public method

Vector2.Lerp(from, to, Time.deltaTime * strength) is not framerate-independent. This function is.
static public SpringLerp ( Vector2 from, Vector2 to, float strength, float deltaTime ) : Vector2
from Vector2
to Vector2
strength float
deltaTime float
return Vector2

SpringLerp() static public method

Vector3.Lerp(from, to, Time.deltaTime * strength) is not framerate-independent. This function is.
static public SpringLerp ( Vector3 from, Vector3 to, float strength, float deltaTime ) : Vector3
from Vector3
to Vector3
strength float
deltaTime float
return Vector3

SpringLerp() static public method

Calculate how much to interpolate by.
static public SpringLerp ( float strength, float deltaTime ) : float
strength float
deltaTime float
return float

SpringLerp() static public method

Mathf.Lerp(from, to, Time.deltaTime * strength) is not framerate-independent. This function is.
static public SpringLerp ( float from, float to, float strength, float deltaTime ) : float
from float
to float
strength float
deltaTime float
return float