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

Base class for all UI components that should be derived from when creating new widget types. More...

Inheritance diagram for UIWidget:
UIRect UIBasicSprite UILabel UI2DSprite UISprite UITexture

Public Types

enum  Pivot {
  Pivot.TopLeft, Pivot.Top, Pivot.TopRight, Pivot.Left,
  Pivot.Center, Pivot.Right, Pivot.BottomLeft, Pivot.Bottom,
  Pivot.BottomRight
}
 
enum  AspectRatioSource { AspectRatioSource.Free, AspectRatioSource.BasedOnWidth, AspectRatioSource.BasedOnHeight }
 
- Public Types inherited from UIRect
enum  AnchorUpdate { AnchorUpdate.OnEnable, AnchorUpdate.OnUpdate, AnchorUpdate.OnStart }
 

Public Member Functions

delegate void OnDimensionsChanged ()
 
delegate void OnPostFillCallback (UIWidget widget, int bufferOffset, BetterList< Vector3 > verts, BetterList< Vector2 > uvs, BetterList< Color32 > cols)
 
delegate bool HitCheck (Vector3 worldPos)
 
void SetDimensions (int w, int h)
 Adjust the widget's dimensions without going through the anchor validation logic. More...
 
override Vector3[] GetSides (Transform relativeTo)
 Get the sides of the rectangle relative to the specified transform. The order is left, top, right, bottom. More...
 
override float CalculateFinalAlpha (int frameID)
 Widget's final alpha, after taking the panel's alpha into account. More...
 
override void Invalidate (bool includeChildren)
 Update the widget's visibility and final alpha. More...
 
float CalculateCumulativeAlpha (int frameID)
 Same as final alpha, except it doesn't take own visibility into consideration. Used by panels. More...
 
override void SetRect (float x, float y, float width, float height)
 Set the widget's rectangle. More...
 
void ResizeCollider ()
 Adjust the widget's collider size to match the widget's dimensions. More...
 
Bounds CalculateBounds ()
 Calculate the widget's bounds, optionally making them relative to the specified transform. More...
 
Bounds CalculateBounds (Transform relativeParent)
 Calculate the widget's bounds, optionally making them relative to the specified transform. More...
 
void SetDirty ()
 Mark the widget as changed so that the geometry can be rebuilt. More...
 
void RemoveFromPanel ()
 Remove this widget from the panel. More...
 
virtual void MarkAsChanged ()
 Tell the panel responsible for the widget that something has changed and the buffers need to be rebuilt. More...
 
UIPanel CreatePanel ()
 Ensure we have a panel referencing this widget. More...
 
void CheckLayer ()
 Check to ensure that the widget resides on the same layer as its panel. More...
 
override void ParentHasChanged ()
 Checks to ensure that the widget is still parented to the right panel. More...
 
bool UpdateVisibility (bool visibleByAlpha, bool visibleByPanel)
 Update the widget's visibility state. More...
 
bool UpdateTransform (int frame)
 Check to see if the widget has moved relative to the panel that manages it More...
 
bool UpdateGeometry (int frame)
 Update the widget and fill its geometry if necessary. Returns whether something was changed. More...
 
void WriteToBuffers (BetterList< Vector3 > v, BetterList< Vector2 > u, BetterList< Color32 > c, BetterList< Vector3 > n, BetterList< Vector4 > t)
 Append the local geometry buffers to the specified ones. More...
 
virtual void MakePixelPerfect ()
 Make the widget pixel-perfect. More...
 
virtual void OnFill (BetterList< Vector3 > verts, BetterList< Vector2 > uvs, BetterList< Color32 > cols)
 Virtual function called by the UIPanel that fills the buffers. More...
 
- Public Member Functions inherited from UIRect
void Update ()
 Rectangles need to update in a specific order – parents before children. When deriving from this class, override its OnUpdate() function instead. More...
 
void UpdateAnchors ()
 Manually update anchored sides. More...
 
void SetAnchor (Transform t)
 Anchor this rectangle to the specified transform. Note that this function will not keep the rectangle's current dimensions, but will instead assume the target's dimensions. More...
 
void SetAnchor (GameObject go)
 Anchor this rectangle to the specified transform. Note that this function will not keep the rectangle's current dimensions, but will instead assume the target's dimensions. More...
 
void SetAnchor (GameObject go, int left, int bottom, int right, int top)
 Anchor this rectangle to the specified transform. More...
 
void ResetAnchors ()
 Ensure that all rect references are set correctly on the anchors. More...
 
void ResetAndUpdateAnchors ()
 Convenience method that resets and updates the anchors, all at once. More...
 

Static Public Member Functions

static int FullCompareFunc (UIWidget left, UIWidget right)
 Static widget comparison function used for depth sorting. More...
 
static int PanelCompareFunc (UIWidget left, UIWidget right)
 Static widget comparison function used for inter-panel depth sorting. More...
 

Public Attributes

OnDimensionsChanged onChange
 Notification triggered when the widget's dimensions or position changes. More...
 
OnPostFillCallback onPostFill
 Notification triggered after the widget's buffer has been filled. More...
 
UIDrawCall.OnRenderCallback mOnRender
 Callback triggered when the widget is about to be renderered (OnWillRenderObject). NOTE: This property is only exposed for the sake of speed to avoid property execution. In most cases you will want to use UIWidget.onRender instead. More...
 
bool autoResizeBoxCollider = false
 If set to 'true', the box collider's dimensions will be adjusted to always match the widget whenever it resizes. More...
 
bool hideIfOffScreen = false
 Hide the widget if it happens to be off-screen. More...
 
AspectRatioSource keepAspectRatio = AspectRatioSource.Free
 Whether the rectangle will attempt to maintain a specific aspect ratio. More...
 
float aspectRatio = 1f
 If you want the anchored rectangle to keep a specific aspect ratio, set this value. More...
 
HitCheck hitCheck
 Custom hit check function. If set, all hit checks (including events) will call this function, passing the world position. Return 'true' if it's within the bounds of your choice, 'false' otherwise. More...
 
UIPanel panel
 Panel that's managing this widget. More...
 
UIGeometry geometry = new UIGeometry()
 Widget's generated geometry. More...
 
bool fillGeometry = true
 If set to 'false', the widget's OnFill function will not be called, letting you define custom geometry at will. More...
 
UIDrawCall drawCall
 Internal usage – draw call that's drawing the widget. More...
 
- Public Attributes inherited from UIRect
AnchorPoint leftAnchor = new AnchorPoint()
 Left side anchor. More...
 
AnchorPoint rightAnchor = new AnchorPoint(1f)
 Right side anchor. More...
 
AnchorPoint bottomAnchor = new AnchorPoint()
 Bottom side anchor. More...
 
AnchorPoint topAnchor = new AnchorPoint(1f)
 Top side anchor. More...
 
AnchorUpdate updateAnchors = AnchorUpdate.OnUpdate
 Whether anchors will be recalculated on every update. More...
 
float finalAlpha = 1f
 Final calculated alpha. More...
 

Protected Member Functions

override void OnEnable ()
 Automatically find the parent rectangle. More...
 
void UpdateFinalAlpha (int frameID)
 Force-calculate the final alpha value. More...
 
virtual void Awake ()
 Remember whether we're in play mode. More...
 
override void OnInit ()
 Mark the widget and the panel as having been changed. More...
 
virtual void UpgradeFrom265 ()
 Facilitates upgrading from NGUI 2.6.5 or earlier versions. More...
 
override void OnStart ()
 Virtual Start() functionality for widgets. More...
 
override void OnAnchor ()
 Update the anchored edges and ensure the widget is registered with a panel. More...
 
override void OnUpdate ()
 Ensure we have a panel to work with. More...
 
override void OnDisable ()
 Clear references. More...
 
- Protected Member Functions inherited from UIRect
Vector3 GetLocalPos (AnchorPoint ac, Transform trans)
 Helper function that gets the specified anchor's position relative to the chosen transform. More...
 
void Start ()
 Set anchor rect references on start. More...
 

Protected Attributes

Color mColor = Color.white
 
Pivot mPivot = Pivot.Center
 
int mWidth = 100
 
int mHeight = 100
 
int mDepth = 0
 
bool mPlayMode = true
 
Vector4 mDrawRegion = new Vector4(0f, 0f, 1f, 1f)
 
Vector3[] mCorners = new Vector3[4]
 
CanvasRenderer mRen
 
- Protected Attributes inherited from UIRect
GameObject mGo
 
Transform mTrans
 
BetterList< UIRectmChildren = new BetterList<UIRect>()
 
bool mChanged = true
 
bool mStarted = false
 
bool mParentFound = false
 
Camera mCam
 

Properties

UIDrawCall.OnRenderCallback onRender [get, set]
 Set the callback that will be triggered when the widget is being rendered (OnWillRenderObject). This is where you would set material properties and shader values. More...
 
CanvasRenderer canvasRenderer [get]
 Canvas renderer that's responsible for the widget's geometry, if there is one present. More...
 
Vector4 drawRegion [get, set]
 Draw region alters how the widget looks without modifying the widget's rectangle. A region is made up of 4 relative values (0-1 range). The order is Left (X), Bottom (Y), Right (Z) and Top (W). To have a widget's left edge be 30% from the left side, set X to 0.3. To have the widget's right edge be 30% from the right hand side, set Z to 0.7. More...
 
Vector2 pivotOffset [get]
 Pivot offset in relative coordinates. Bottom-left is (0, 0). Top-right is (1, 1). More...
 
int width [get, set]
 Widget's width in pixels. More...
 
int height [get, set]
 Widget's height in pixels. More...
 
Color color [get, set]
 Color used by the widget. More...
 
override float alpha [get, set]
 Widget's alpha – a convenience method. More...
 
bool isVisible [get]
 Whether the widget is currently visible. More...
 
bool hasVertices [get]
 Whether the widget has vertices to draw. More...
 
Pivot rawPivot [get, set]
 Change the pivot point and do not attempt to keep the widget in the same place by adjusting its transform. More...
 
Pivot pivot [get, set]
 Set or get the value that specifies where the widget's pivot point should be. More...
 
int depth [get, set]
 Depth controls the rendering order – lowest to highest. More...
 
int raycastDepth [get]
 Raycast depth order on widgets takes the depth of their panel into consideration. This functionality is used to determine the "final" depth of the widget for drawing and raycasts. More...
 
override Vector3[] localCorners [get]
 Local space corners of the widget. The order is bottom-left, top-left, top-right, bottom-right. More...
 
virtual Vector2 localSize [get]
 Local width and height of the widget in pixels. More...
 
Vector3 localCenter [get]
 Widget's center in local coordinates. Don't forget to transform by the widget's transform. More...
 
override Vector3[] worldCorners [get]
 World-space corners of the widget. The order is bottom-left, top-left, top-right, bottom-right. More...
 
Vector3 worldCenter [get]
 World-space center of the widget. More...
 
virtual Vector4 drawingDimensions [get]
 Local space region where the actual drawing will take place. X = left, Y = bottom, Z = right, W = top. More...
 
virtual Material material [get, set]
 Material used by the widget. More...
 
virtual Texture mainTexture [get, set]
 Texture used by the widget. More...
 
virtual Shader shader [get, set]
 Shader is used to create a dynamic material if the widget has no material to work with. More...
 
Vector2 relativeSize [get]
 Do not use this, it's obsolete. More...
 
bool hasBoxCollider [get]
 Convenience function that returns 'true' if the widget has a box collider. More...
 
virtual int minWidth [get]
 Minimum allowed width for this widget. More...
 
virtual int minHeight [get]
 Minimum allowed height for this widget. More...
 
virtual Vector4 border [get, set]
 Dimensions of the sprite's border, if any. More...
 
- Properties inherited from UIRect
GameObject cachedGameObject [get]
 Game object gets cached for speed. Can't simply return 'mGo' set in Awake because this function may be called on a prefab. More...
 
Transform cachedTransform [get]
 Transform gets cached for speed. Can't simply return 'mTrans' set in Awake because this function may be called on a prefab. More...
 
Camera anchorCamera [get]
 Camera used by anchors. More...
 
bool isFullyAnchored [get]
 Whether the rectangle is currently anchored fully on all sides. More...
 
virtual bool isAnchoredHorizontally [get]
 Whether the rectangle is anchored horizontally. More...
 
virtual bool isAnchoredVertically [get]
 Whether the rectangle is anchored vertically. More...
 
virtual bool canBeAnchored [get]
 Whether the rectangle can be anchored. More...
 
UIRect parent [get]
 Get the rectangle's parent, if any. More...
 
UIRoot root [get]
 Get the root object, if any. More...
 
bool isAnchored [get]
 Returns 'true' if the widget is currently anchored on any side. More...
 
abstract float alpha [get, set]
 Local alpha, not relative to anything. More...
 
abstract Vector3[] localCorners [get]
 Local-space corners of the UI rectangle. The order is bottom-left, top-left, top-right, bottom-right. More...
 
abstract Vector3[] worldCorners [get]
 World-space corners of the UI rectangle. The order is bottom-left, top-left, top-right, bottom-right. More...
 
float cameraRayDistance [get]
 Helper function that returns the distance to the camera's directional vector hitting the panel's plane. More...
 

Additional Inherited Members

- Static Protected Attributes inherited from UIRect
static Vector3[] mSides = new Vector3[4]
 

Detailed Description

Base class for all UI components that should be derived from when creating new widget types.

Member Enumeration Documentation

Enumerator
Free 
BasedOnWidth 
BasedOnHeight 
Enumerator
TopLeft 
Top 
TopRight 
Left 
Center 
Right 
BottomLeft 
Bottom 
BottomRight 

Member Function Documentation

virtual void UIWidget.Awake ( )
protectedvirtual

Remember whether we're in play mode.

Bounds UIWidget.CalculateBounds ( )

Calculate the widget's bounds, optionally making them relative to the specified transform.

Bounds UIWidget.CalculateBounds ( Transform  relativeParent)

Calculate the widget's bounds, optionally making them relative to the specified transform.

float UIWidget.CalculateCumulativeAlpha ( int  frameID)

Same as final alpha, except it doesn't take own visibility into consideration. Used by panels.

override float UIWidget.CalculateFinalAlpha ( int  frameID)
virtual

Widget's final alpha, after taking the panel's alpha into account.

Implements UIRect.

void UIWidget.CheckLayer ( )

Check to ensure that the widget resides on the same layer as its panel.

UIPanel UIWidget.CreatePanel ( )

Ensure we have a panel referencing this widget.

static int UIWidget.FullCompareFunc ( UIWidget  left,
UIWidget  right 
)
static

Static widget comparison function used for depth sorting.

override Vector3 [] UIWidget.GetSides ( Transform  relativeTo)
virtual

Get the sides of the rectangle relative to the specified transform. The order is left, top, right, bottom.

Reimplemented from UIRect.

Reimplemented in UILabel.

delegate bool UIWidget.HitCheck ( Vector3  worldPos)
override void UIWidget.Invalidate ( bool  includeChildren)
virtual

Update the widget's visibility and final alpha.

Reimplemented from UIRect.

virtual void UIWidget.MakePixelPerfect ( )
virtual

Make the widget pixel-perfect.

Reimplemented in UILabel, UISprite, UI2DSprite, and UITexture.

virtual void UIWidget.MarkAsChanged ( )
virtual

Tell the panel responsible for the widget that something has changed and the buffers need to be rebuilt.

Reimplemented in UILabel.

override void UIWidget.OnAnchor ( )
protectedvirtual

Update the anchored edges and ensure the widget is registered with a panel.

Implements UIRect.

Reimplemented in UILabel.

delegate void UIWidget.OnDimensionsChanged ( )
override void UIWidget.OnDisable ( )
protectedvirtual

Clear references.

Reimplemented from UIRect.

Reimplemented in UILabel.

override void UIWidget.OnEnable ( )
protectedvirtual

Automatically find the parent rectangle.

Reimplemented from UIRect.

virtual void UIWidget.OnFill ( BetterList< Vector3 >  verts,
BetterList< Vector2 >  uvs,
BetterList< Color32 >  cols 
)
virtual

Virtual function called by the UIPanel that fills the buffers.

Reimplemented in UILabel, UISprite, UI2DSprite, and UITexture.

override void UIWidget.OnInit ( )
protectedvirtual

Mark the widget and the panel as having been changed.

Reimplemented from UIRect.

Reimplemented in UILabel, and UISprite.

delegate void UIWidget.OnPostFillCallback ( UIWidget  widget,
int  bufferOffset,
BetterList< Vector3 >  verts,
BetterList< Vector2 >  uvs,
BetterList< Color32 >  cols 
)
override void UIWidget.OnStart ( )
protectedvirtual

Virtual Start() functionality for widgets.

Implements UIRect.

Reimplemented in UILabel.

override void UIWidget.OnUpdate ( )
protectedvirtual

Ensure we have a panel to work with.

Reimplemented from UIRect.

Reimplemented in UISprite, and UI2DSprite.

static int UIWidget.PanelCompareFunc ( UIWidget  left,
UIWidget  right 
)
static

Static widget comparison function used for inter-panel depth sorting.

override void UIWidget.ParentHasChanged ( )
virtual

Checks to ensure that the widget is still parented to the right panel.

Reimplemented from UIRect.

void UIWidget.RemoveFromPanel ( )

Remove this widget from the panel.

void UIWidget.ResizeCollider ( )

Adjust the widget's collider size to match the widget's dimensions.

void UIWidget.SetDimensions ( int  w,
int  h 
)

Adjust the widget's dimensions without going through the anchor validation logic.

void UIWidget.SetDirty ( )

Mark the widget as changed so that the geometry can be rebuilt.

override void UIWidget.SetRect ( float  x,
float  y,
float  width,
float  height 
)
virtual

Set the widget's rectangle.

Implements UIRect.

void UIWidget.UpdateFinalAlpha ( int  frameID)
protected

Force-calculate the final alpha value.

bool UIWidget.UpdateGeometry ( int  frame)

Update the widget and fill its geometry if necessary. Returns whether something was changed.

bool UIWidget.UpdateTransform ( int  frame)

Check to see if the widget has moved relative to the panel that manages it

bool UIWidget.UpdateVisibility ( bool  visibleByAlpha,
bool  visibleByPanel 
)

Update the widget's visibility state.

virtual void UIWidget.UpgradeFrom265 ( )
protectedvirtual

Facilitates upgrading from NGUI 2.6.5 or earlier versions.

Reimplemented in UILabel.

void UIWidget.WriteToBuffers ( BetterList< Vector3 >  v,
BetterList< Vector2 >  u,
BetterList< Color32 >  c,
BetterList< Vector3 >  n,
BetterList< Vector4 >  t 
)

Append the local geometry buffers to the specified ones.

Member Data Documentation

float UIWidget.aspectRatio = 1f

If you want the anchored rectangle to keep a specific aspect ratio, set this value.

bool UIWidget.autoResizeBoxCollider = false

If set to 'true', the box collider's dimensions will be adjusted to always match the widget whenever it resizes.

UIDrawCall UIWidget.drawCall

Internal usage – draw call that's drawing the widget.

bool UIWidget.fillGeometry = true

If set to 'false', the widget's OnFill function will not be called, letting you define custom geometry at will.

UIGeometry UIWidget.geometry = new UIGeometry()

Widget's generated geometry.

bool UIWidget.hideIfOffScreen = false

Hide the widget if it happens to be off-screen.

HitCheck UIWidget.hitCheck

Custom hit check function. If set, all hit checks (including events) will call this function, passing the world position. Return 'true' if it's within the bounds of your choice, 'false' otherwise.

AspectRatioSource UIWidget.keepAspectRatio = AspectRatioSource.Free

Whether the rectangle will attempt to maintain a specific aspect ratio.

Color UIWidget.mColor = Color.white
protected
Vector3 [] UIWidget.mCorners = new Vector3[4]
protected
int UIWidget.mDepth = 0
protected
Vector4 UIWidget.mDrawRegion = new Vector4(0f, 0f, 1f, 1f)
protected
int UIWidget.mHeight = 100
protected
UIDrawCall.OnRenderCallback UIWidget.mOnRender

Callback triggered when the widget is about to be renderered (OnWillRenderObject). NOTE: This property is only exposed for the sake of speed to avoid property execution. In most cases you will want to use UIWidget.onRender instead.

Pivot UIWidget.mPivot = Pivot.Center
protected
bool UIWidget.mPlayMode = true
protected
CanvasRenderer UIWidget.mRen
protected
int UIWidget.mWidth = 100
protected
OnDimensionsChanged UIWidget.onChange

Notification triggered when the widget's dimensions or position changes.

OnPostFillCallback UIWidget.onPostFill

Notification triggered after the widget's buffer has been filled.

UIPanel UIWidget.panel

Panel that's managing this widget.

Property Documentation

override float UIWidget.alpha
getset

Widget's alpha – a convenience method.

virtual Vector4 UIWidget.border
getset

Dimensions of the sprite's border, if any.

CanvasRenderer UIWidget.canvasRenderer
get

Canvas renderer that's responsible for the widget's geometry, if there is one present.

Color UIWidget.color
getset

Color used by the widget.

int UIWidget.depth
getset

Depth controls the rendering order – lowest to highest.

virtual Vector4 UIWidget.drawingDimensions
get

Local space region where the actual drawing will take place. X = left, Y = bottom, Z = right, W = top.

Vector4 UIWidget.drawRegion
getset

Draw region alters how the widget looks without modifying the widget's rectangle. A region is made up of 4 relative values (0-1 range). The order is Left (X), Bottom (Y), Right (Z) and Top (W). To have a widget's left edge be 30% from the left side, set X to 0.3. To have the widget's right edge be 30% from the right hand side, set Z to 0.7.

bool UIWidget.hasBoxCollider
get

Convenience function that returns 'true' if the widget has a box collider.

bool UIWidget.hasVertices
get

Whether the widget has vertices to draw.

int UIWidget.height
getset

Widget's height in pixels.

bool UIWidget.isVisible
get

Whether the widget is currently visible.

Vector3 UIWidget.localCenter
get

Widget's center in local coordinates. Don't forget to transform by the widget's transform.

override Vector3 [] UIWidget.localCorners
get

Local space corners of the widget. The order is bottom-left, top-left, top-right, bottom-right.

virtual Vector2 UIWidget.localSize
get

Local width and height of the widget in pixels.

virtual Texture UIWidget.mainTexture
getset

Texture used by the widget.

virtual Material UIWidget.material
getset

Material used by the widget.

virtual int UIWidget.minHeight
get

Minimum allowed height for this widget.

virtual int UIWidget.minWidth
get

Minimum allowed width for this widget.

UIDrawCall.OnRenderCallback UIWidget.onRender
getset

Set the callback that will be triggered when the widget is being rendered (OnWillRenderObject). This is where you would set material properties and shader values.

Pivot UIWidget.pivot
getset

Set or get the value that specifies where the widget's pivot point should be.

Vector2 UIWidget.pivotOffset
get

Pivot offset in relative coordinates. Bottom-left is (0, 0). Top-right is (1, 1).

Pivot UIWidget.rawPivot
getset

Change the pivot point and do not attempt to keep the widget in the same place by adjusting its transform.

int UIWidget.raycastDepth
get

Raycast depth order on widgets takes the depth of their panel into consideration. This functionality is used to determine the "final" depth of the widget for drawing and raycasts.

Vector2 UIWidget.relativeSize
get

Do not use this, it's obsolete.

virtual Shader UIWidget.shader
getset

Shader is used to create a dynamic material if the widget has no material to work with.

int UIWidget.width
getset

Widget's width in pixels.

Vector3 UIWidget.worldCenter
get

World-space center of the widget.

override Vector3 [] UIWidget.worldCorners
get

World-space corners of the widget. The order is bottom-left, top-left, top-right, bottom-right.


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