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
children
This UIObject's children.
public List<UIObject> children { get; }
Property Value
fillType
The current fill set on this UIObject.
public FillType fillType { get; }
Property Value
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
inheritTheme
Whether automatic theme inheritance is allowed for this UIObject.
public bool inheritTheme { get; }
Property Value
isVisible
Whether this UIObject is currently set to be visible.
public bool isVisible { get; }
Property Value
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
onBeginDrag
Invokes listeners whenever the cursor has started dragging on this UIObject.
public virtual MouseEvent onBeginDrag { get; }
Property Value
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
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
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
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
tooltip
This UIObject's tooltip.
public string tooltip { get; }
Property Value
width
The currently configured width of this UIObject.
public float width { get; }
Property Value
Methods
Add(UIComponent, bool)
Shorthand for AddContent(UIComponent, bool).
public void Add(UIComponent child, bool setTheme = false)
Parameters
childUIComponentThe child to add
setThemeboolWhether 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
childUIComponentThe child to add
setThemeboolWhether 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
childUIComponentThe child to add
setThemeboolWhether 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
anchorAnchorTypeThe 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
positionVector2The 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
positionVector2The position dragged to
OnEndDrag(Vector2)
Handles the end of this UIObject being dragged.
protected virtual void OnEndDrag(Vector2 position)
Parameters
positionVector2The 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
anchorTypeAnchorTypeThe 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
contentUIComponentThe component which should be the
contentinstead
SetContentLayout(LayoutType)
Sets the layout to be used on the configured content for this UIObject.
public void SetContentLayout(LayoutType layoutType)
Parameters
layoutTypeLayoutTypeThe 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
paddingintThe 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
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
leftintThe left padding to use
rightintThe right padding to use
topintThe top padding to use
bottomintThe 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
alignmentAnchorTypeThe 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
spacingfloatThe 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
fillTypeFillTypeThe 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
inheritThemeboolWhether 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
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
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
themeThemeThe 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
themeThemeThe theme to apply
SetTooltip(string)
Sets the tooltip for this UIObject.
public void SetTooltip(string tooltip)
Parameters
tooltipstringThe tooltip to display
Show()
Shows this UIObject.
public virtual void Show()
ToggleVisibility()
Toggles the visibility of this UIObject.
public virtual void ToggleVisibility()