Table of Contents

Class UIObject

Namespace
UILib
Assembly
UILib.dll

The base class which most objects inherit from.

You'd rarely want to use this class directly though. Most of the time you'd want to use UIComponent or something like an Overlay or Window.

Provides most of the necessary functionality.

public abstract class UIObject
Inheritance
UIObject
Derived
Inherited Members

Constructors

UIObject()

Initializes a UIObject.

public UIObject()

Properties

anchorType

The current anchor set on this UIObject.

public AnchorType anchorType { get; }

Property Value

AnchorType

children

This UIObject's children.

public List<UIObject> children { get; }

Property Value

List<UIObject>

fillType

The current fill set on this UIObject.

public FillType fillType { get; }

Property Value

FillType

fitter

The ContentSizeFitter for this UIObject's content, if it has one. It's important to note that this is added to the configured content.

public ContentSizeFitter fitter { get; }

Property Value

ContentSizeFitter

gameObject

The underlying GameObject this UIObject attaches components to.

public GameObject gameObject { get; }

Property Value

GameObject

height

The currently configured height of this UIObject.

public float height { get; }

Property Value

float

inheritTheme

Whether automatic theme inheritance is allowed for this UIObject.

public bool inheritTheme { get; }

Property Value

bool

isVisible

Whether this UIObject is currently set to be visible.

public bool isVisible { get; }

Property Value

bool

layoutElement

The LayoutElement for this UIObject, if it has one.

public LayoutElement layoutElement { get; }

Property Value

LayoutElement

layoutGroup

The LayoutGroup for this UIObject's content, if it has one. It's important to note that this is added to the configured content, not necessarily on the gameObject.

public HorizontalOrVerticalLayoutGroup layoutGroup { get; }

Property Value

HorizontalOrVerticalLayoutGroup

layoutType

The current layout set on this UIObject's content. It's important to note that this is set on the configured content.

public LayoutType layoutType { get; }

Property Value

LayoutType

onBeginDrag

Invokes listeners whenever the cursor has started dragging on this UIObject.

public virtual MouseEvent onBeginDrag { get; }

Property Value

MouseEvent

onClick

Invokes listeners whenever this UIObject is clicked.

public virtual UnityEvent onClick { get; }

Property Value

UnityEvent

onDisable

Invokes listeners when this UIObject is disabled (hidden).

public virtual UnityEvent onDisable { get; }

Property Value

UnityEvent

onDoubleClick

Invokes listeners whenever this UIObject is double clicked.

public virtual UnityEvent onDoubleClick { get; }

Property Value

UnityEvent

onDrag

Invokes listeners whenever the cursor is dragging on this UIObject.

public virtual MouseEvent onDrag { get; }

Property Value

MouseEvent

onEnable

Invokes listeners when this UIObject is enabled (shown).

public virtual UnityEvent onEnable { get; }

Property Value

UnityEvent

onEndDrag

Invokes listeners whenever the cursor has stopped dragging on this UIObject.

public virtual MouseEvent onEndDrag { get; }

Property Value

MouseEvent

onPointerDown

Invokes listeners when the pointer is held down on this UIObject.

public virtual UnityEvent onPointerDown { get; }

Property Value

UnityEvent

onPointerEnter

Invokes listeners whenever this UIObject is hovered over.

public virtual UnityEvent onPointerEnter { get; }

Property Value

UnityEvent

onPointerExit

Invokes listeners whenever this UIObject is no longer hovered over.

public virtual UnityEvent onPointerExit { get; }

Property Value

UnityEvent

onPointerUp

Invokes listeners when the pointer is no longer being held down on this UIObject.

public virtual UnityEvent onPointerUp { get; }

Property Value

UnityEvent

parent

The parent of this UIObject.

public UIObject parent { get; }

Property Value

UIObject

rectTransform

The RectTransform attached to gameObject.

public RectTransform rectTransform { get; }

Property Value

RectTransform

theme

The theme currently applied to this UIObject.

public Theme theme { get; }

Property Value

Theme

tooltip

This UIObject's tooltip.

public string tooltip { get; }

Property Value

string

width

The currently configured width of this UIObject.

public float width { get; }

Property Value

float

Methods

Add(UIComponent, bool)

public void Add(UIComponent child, bool setTheme = false)

Parameters

child UIComponent

The child to add

setTheme bool

Whether the child should inherit the content's theme immediately

AddContent(UIComponent, bool)

Adds a component to the content.

public virtual void AddContent(UIComponent child, bool setTheme = false)

Parameters

child UIComponent

The child to add

setTheme bool

Whether the child should inherit the content's theme immediately

AddDirect(UIComponent, bool)

Adds a component directly to this UIObject, ignoring the configured content.

public virtual void AddDirect(UIComponent child, bool setTheme = false)

Parameters

child UIComponent

The child to add

setTheme bool

Whether the child should inherit this object's theme immediately

AddLayoutElement()

Adds a LayoutElement to this UIObject to allow automatically managing how it's layed out in its parent container.

In general, you won't need to call this since whenever you add a UIObject to another, it will automatically get a LayoutElement if the parent being added to has a layout configured already.

LayoutElements only do anything if the parent container has a layout set on it (vertical or horizontal).

public void AddLayoutElement()

AnchorToText(AnchorType)

Converts an AnchorType to a Unity TextAnchor.

public TextAnchor AnchorToText(AnchorType anchor)

Parameters

anchor AnchorType

The anchor to convert

Returns

TextAnchor

The converted anchor

Destroy()

Destroys this UIObject and all children.

public virtual void Destroy()

Hide()

Hides this UIObject.

public virtual void Hide()

OnBeginDrag(Vector2)

Handles the start of this UIObject being dragged.

protected virtual void OnBeginDrag(Vector2 position)

Parameters

position Vector2

The position the drag started at

OnClick()

Handles this UIObject being clicked.

protected virtual void OnClick()

OnDoubleClick()

Handles this UIObject being double clicked.

protected virtual void OnDoubleClick()

OnDrag(Vector2)

Handles this UIObject being dragged.

protected virtual void OnDrag(Vector2 position)

Parameters

position Vector2

The position dragged to

OnEndDrag(Vector2)

Handles the end of this UIObject being dragged.

protected virtual void OnEndDrag(Vector2 position)

Parameters

position Vector2

The position the drag ended at

OnPointerDown()

Handles the pointer being held down on this UIObject.

protected virtual void OnPointerDown()

OnPointerEnter()

Handles this UIObject being hovered over.

protected virtual void OnPointerEnter()

OnPointerExit()

Handles this UIObject no longer being hovered over.

protected virtual void OnPointerExit()

OnPointerUp()

Handles the pointer no longer being held down on this UIObject.

protected virtual void OnPointerUp()

SetAnchor(AnchorType)

Sets the anchor type of this UIObject. This determines how it will be positioned within its parent container.

public void SetAnchor(AnchorType anchorType)

Parameters

anchorType AnchorType

The type of anchor to use

SetContent(UIComponent)

Sets a different component to be the content.

By default, the content will just be the gameObject of this UIObject. However, some components need to set custom content objects as in some cases the children should be added to a different UIObject.

A good example of this would be ScrollViews, which are composed of a variety of GameObjects like so:

- ScrollView
  - Viewport
    - Content
  - ScrollBar
  - ScrollBar

In general adding to the ScrollView directly doesn't make much sense, you usually want to add to the "Content" GameObject instead. So, ScrollViews configure their content to be "Content", rather than "ScrollView".

public virtual void SetContent(UIComponent content)

Parameters

content UIComponent

The component which should be the content instead

SetContentLayout(LayoutType)

Sets the layout to be used on the configured content for this UIObject.

public void SetContentLayout(LayoutType layoutType)

Parameters

layoutType LayoutType

The type of layout to use

SetContentPadding(int)

Sets the padding to apply to the content.

This requires you to have already called SetContentLayout(LayoutType) to configure a layout for the content.

public void SetContentPadding(int padding)

Parameters

padding int

The padding to use all around

SetContentPadding(int, int)

Sets the padding to apply to the content.

This requires you to have already called SetContentLayout(LayoutType) to configure a layout for the content.

public void SetContentPadding(int horizontal, int vertical)

Parameters

horizontal int

The horizontal padding to use

vertical int

The vertical padding to use

SetContentPadding(int, int, int, int)

Sets the padding to apply to the content.

This requires you to have already called SetContentLayout(LayoutType) to configure a layout for the content.

public void SetContentPadding(int left = 0, int right = 0, int top = 0, int bottom = 0)

Parameters

left int

The left padding to use

right int

The right padding to use

top int

The top padding to use

bottom int

The bottom padding to use

SetElementAlignment(AnchorType)

Sets the alignment of the child elements of the content.

This requires you to have already called SetContentLayout(LayoutType) to configure a layout for the content.

public void SetElementAlignment(AnchorType alignment)

Parameters

alignment AnchorType

The alignment to use

SetElementSpacing(float)

Sets the spacing between child elements of the content.

This requires you to have already called SetContentLayout(LayoutType) to configure a layout for the content.

public void SetElementSpacing(float spacing)

Parameters

spacing float

The spacing to use

SetFill(FillType)

Sets the fill type of this UIObject. This determines how this UIObject will fill its parent container.

public void SetFill(FillType fillType)

Parameters

fillType FillType

The type of fill to use

SetInheritTheme(bool)

Determines whether this UIObject can automatically inherit its parent's theme on a SetTheme.

If this is true, this UIObject can inherit the theme from its parent on a SetTheme call

If this is false, this UIObject won't be able to automatically inherit the theme from the parent. Calls to SetTheme(Theme) on this object will still work though.

public void SetInheritTheme(bool inheritTheme)

Parameters

inheritTheme bool

Whether theme inheriting is allowed

SetOffset(float, float)

Sets an offset for this UIObject from its current anchor.

public void SetOffset(float x, float y)

Parameters

x float

The x offset to set

y float

The y offset to set

SetSize(float, float)

Sets the size of this UIObject.

If you use a certain fill, this size behaves differently. Instead of being the actual width and height of the UIObject, they will add/subtract from the width/height, depending on which fills are used.

If you don't use a fill, both width and height will remain as the width and height. Their behaviour will be unchanged.

If you use a Horizontal fill, you could specify a width such as -20f to subtract 20 pixels from the full width.

If you use a Vertical fill, you could specify a height such as 100f and it would add 100 pixels to the full height.

Similarly, if you use choose to fill All the space, any positive values will increase this UIObject beyond its normal fill. Any negative values will decrease it from its normal fill.

public virtual void SetSize(float width, float height)

Parameters

width float

The width to set

height float

The height to set

SetTheme(Theme)

Allows setting the theme of this UIObject and all children.

Passing a theme of null will result in the default theme being applied instead.

public virtual void SetTheme(Theme theme)

Parameters

theme Theme

The theme to apply

SetThisTheme(Theme)

Allows setting the theme of just this UIObject.

This handles setting the theme specifically for this UIObject, not its children.

In most cases, you'd probably want to use SetTheme(Theme) instead.

protected abstract void SetThisTheme(Theme theme)

Parameters

theme Theme

The theme to apply

SetTooltip(string)

Sets the tooltip for this UIObject.

public void SetTooltip(string tooltip)

Parameters

tooltip string

The tooltip to display

Show()

Shows this UIObject.

public virtual void Show()

ToggleVisibility()

Toggles the visibility of this UIObject.

public virtual void ToggleVisibility()