Table of Contents

Class Button

Namespace
Fallencake.UI
Assembly
Fallencake.UI.dll

Modular, multi-graphic UI button with single- and double-click support, group selection behavior, and optional click ripple effects.

[AddComponentMenu("Modular UI/Button", 30)]
[ExecuteAlways]
public class Button : MultipleGraphicsSelectable, IMultiSelectable, IMultipleClicksHandler, IGroupSelectable
Inheritance
object
Object
Component
Behaviour
MonoBehaviour
UIBehaviour
Selectable
Button
Implements
Inherited Members

Remarks

Composes multiple icons and text labels for each visual state and coordinates their transitions via MultipleGraphicsSelectable. Supports double-click detection using DoubleClickInterval and EnableInstantFirstClickEvent, and can participate in a SelectableGroup to synchronize selection within a group. Optionally spawns a ripple effect on pointer down.

Fields

ClickEffectMaxScale

Maximum uniform scale the ripple can reach before it is destroyed.

[Range(0.5, 25)]
public float ClickEffectMaxScale

Field Value

float

ClickEffectParent

The parent UnityEngine.Transform that will host the ripple effect GameObject.

public Transform ClickEffectParent

Field Value

Transform

ClickEffectSpeed

Playback speed multiplier for the ripple animation.

[Range(0.1, 5)]
public float ClickEffectSpeed

Field Value

float

ClickEffectStartColor

Starting color (including alpha) of the ripple.

public Color ClickEffectStartColor

Field Value

Color

ClickEffectTargetColor

Target color (including alpha) the ripple fades to.

public Color ClickEffectTargetColor

Field Value

Color

ClickEffectTexture

The sprite used by the ripple effect image.

public Sprite ClickEffectTexture

Field Value

Sprite

DoubleClickInterval

The interval in seconds between the first click and the second click to trigger the OnDoubleClick event.

[Range(0.1, 1)]
public float DoubleClickInterval

Field Value

float

EnableClickEffect

Enables or disables the visual ripple effect on pointer down.

public bool EnableClickEffect

Field Value

bool

Remarks

When enabled, CreateRippleEffect(Vector2) instantiates a transient RippleEffect on ClickEffectParent configured by the fields below.

EnableDoubleClick

If true, the button will trigger the OnDoubleClick event when the user clicks the button twice within the DoubleClickInterval seconds.

public bool EnableDoubleClick

Field Value

bool

EnableInstantFirstClickEvent

When true, the OnClick event will be triggered immediately when the button is clicked. If false, the event will be triggered after the DoubleClickInterval seconds.

public bool EnableInstantFirstClickEvent

Field Value

bool

IsCenteredPosition

If true, spawns the ripple at the center of ClickEffectParent; otherwise uses the pointer position.

public bool IsCenteredPosition

Field Value

bool

IsRenderOnTop

If true, forces ClickEffectParent to be rendered on top by moving it to the end of the sibling list.

public bool IsRenderOnTop

Field Value

bool

OnClickEffectUpdateMode

Determines whether the ripple animation uses scaled or unscaled time.

public ClickEffectUpdateMode OnClickEffectUpdateMode

Field Value

ClickEffectUpdateMode

Properties

IsIconEnabled

Whether icon graphics are enabled and synchronized across button states.

public bool IsIconEnabled { get; set; }

Property Value

bool

Setting this property immediately toggles icon GameObjects using SetIconEnabled(bool).

IsTextEnabled

Whether text label graphics are enabled across button states.

public bool IsTextEnabled { get; set; }

Property Value

bool

Setting this property immediately toggles text label GameObjects using SetTextLabelEnabled(bool).

OnClick

UnityEvent that is triggered when the button is pressed once. Note: Triggered on MouseUp after MouseDown on the same object.

public OnButtonClickedEvent OnClick { get; set; }

Property Value

OnButtonClickedEvent

OnDoubleClick

UnityEvent that is triggered when the button is pressed twice for a short period of time.

public OnButtonClickedEvent OnDoubleClick { get; set; }

Property Value

OnButtonClickedEvent

Methods

CreateRippleEffect(Vector2)

Spawns a ripple effect at the given screen-space position or at the center depending on IsCenteredPosition.

public void CreateRippleEffect(Vector2 position)

Parameters

position Vector2

Screen position in pixels where the ripple should appear.

ForceSelected(bool)

Forces the button's selected flag and refreshes its visuals, regardless of group presence.

public void ForceSelected(bool selected)

Parameters

selected bool

Whether the button should appear selected.

HandleDoubleClickCheck()

Method that handles the check for double click on button to trigger OnDoubleClick event. You can call it from OnPointerClick method.

public void HandleDoubleClickCheck()

Remarks

If EnableDoubleClick is disabled, immediately performs a normal click. Otherwise uses DoubleClickInterval to detect the second click and optionally fires the first click instantly depending on EnableInstantFirstClickEvent.

SetGroup(SelectableGroup)

Assigns the group that manages this button's selection state.

public void SetGroup(SelectableGroup group)

Parameters

group SelectableGroup

The SelectableGroup to associate with this button.

SetIconEnabled(bool)

Toggle the visibility of the icon. If _isIconControlsParent is true, the icon's parent will be toggled instead of the icon itself.

public void SetIconEnabled(bool isActive)

Parameters

isActive bool

If true, the icon will be visible. If false, the icon will be hidden.

SetSelectedInGroup(bool)

Sets this button's selected state within its group and updates visuals.

public void SetSelectedInGroup(bool selected)

Parameters

selected bool

If true, forces the button into the Selected state in its group.

SetTextLabelEnabled(bool)

Toggle the visibility of the text label.

public void SetTextLabelEnabled(bool isActive)

Parameters

isActive bool

If true, the text label will be visible. If false, the text label will be hidden.

See Also