Table of Contents

Class Button

Namespace
UILib.Components
Assembly
UILib.dll

A button component.

Buttons can have textures or text on them and handle click events.

public class Button : UIComponent
Inheritance
Button
Derived
Inherited Members

Constructors

Button()

Initializes a blank button.

public Button()

Button(string, int)

Initializes a button with the specified text.

public Button(string text, int fontSize)

Parameters

text string

The text to add to this button

fontSize int

The font size for the text

Button(Texture2D)

Initializes a button with a texture.

public Button(Texture2D texture)

Parameters

texture Texture2D

The texture to add to this button

Properties

background

The button's background.

public Image background { get; }

Property Value

Image

button

The underlying Unity Button.

public Button button { get; }

Property Value

Button

image

The image attached to this button, if any.

public Image image { get; }

Property Value

Image

label

The label attached to this button, if any.

public Label label { get; }

Property Value

Label

onClick

Invokes listeners when this button is clicked.

public override UnityEvent onClick { get; }

Property Value

UnityEvent

playSound

Whether this button will play the navigation sound when clicked.

public bool playSound { get; }

Property Value

bool

Methods

SetBackground(Texture2D)

Allows changing the background image of the button.

public void SetBackground(Texture2D texture)

Parameters

texture Texture2D

The texture to use instead

SetPlaySound(bool)

Sets whether this button should play the navigation sound.

public void SetPlaySound(bool playSound)

Parameters

playSound bool

Whether this button should play a sound

SetText(string)

Sets the text on this button.

public void SetText(string text)

Parameters

text string

The text to set

SetTexture(Texture2D)

Sets the texture on this button.

public void SetTexture(Texture2D texture)

Parameters

texture Texture2D

SetThisTheme(Theme)

Allows setting the theme of this button.

This handles setting the theme specifically for this component, not its children. It's protected to allow overriding if you were to create a subclass.

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

protected override void SetThisTheme(Theme theme)

Parameters

theme Theme

The theme to apply