Home › Page › UghSurface

UghSurface

UghSurface

Inherits from MonoBehaviour.

UghSurface is a class that programmatically arranges a list of children.  The surface can lay the children out in either a vertical or horizontal direction.  The children components will be arranged from end-to-end.  Each child must contain an UghSurfaceHint to define its size and shape.

The UghSurface can be assigned a backing element.  This element will be scaled and positioned such that it can encapsulate all child elements.  This backing element must also contain an UghSurfaceHint.

Class Variables
name type description
layoutDirection LayoutDirection The direction children should be arranged.
constantWidth float When layoutDirection is Horizontal, this is the width the surface is allowed to grow until children wrap down to the next row.  If -1, this will be ignored.
constantHight float When layoutDirection is Vertical, this is the height the surface is allowed to grow until children wrap over to the next column.  If -1, this will be ignored.
backingElement UghSurfaceHint A GameObject that will be scaled and positioned to encapsulate all child elements.
leftMargin float An amount of space, in Unity units, added to the left side of the surface before children are laid out.
rightMargin float An amount of space, in Unity units, added to the right side of the surface before children are laid out.
topMargin float An amount of space, in Unity units, added to the top side of the surface before children are laid out.
bottomMargin float An amount of space, in Unity units, added to the bottom side of the surface before children are laid out.
autosizeCollider bool If true and this UghSurface has a BoxCollider, the collider will be scaled to contain all of its child elements.
childElements List<UghSurfaceHint> The list of child elements to be arranged.
IsDirty bool If this surface will call the Layout() function during its next Update().
SurfaceSize Vector2 Read only.  The width and height of the surface, in Unity units.
Class Functions
name type description
SetUghSurfaceDirty void Marks this surface as dirty. It will call Layout() during the next Update().
AddChild void Adds the given UghSurfaceHint object to the list of child elements and then calls Layout().
InsertChild void Inserts the given UghSurfaceHint object into the list of child elements at the given index and then calls Layout().
Layout void Arranges the child elements and then resizes any backing element.

-

Understanding UghSurface

For UghSurface to function, you must add objects to the childElements list.  You can do this in one of three ways:  by directly adding the child to the childElements list, by using the Add function, or by using the InsertChild function.  The Add and InsertChild functions accept a single object and then immediately call the Layout function.  If you intend to add more than one child at a time, it is best to directly add them to the childElement list and then either call Layout or set IsDirty to true.

UghSurface can be given child elements before runtime.  In the inspector, add objects to the childElement list.  Layout will be called once during the UghSurface’s Start function.