Table of Contents

Class MultipleGraphicsSelectable

Namespace
Fallencake.UI
Assembly
Fallencake.UI.dll

Base selectable that orchestrates transitions for multiple UI graphics when its selection state changes.

public class MultipleGraphicsSelectable : Selectable, IMultiSelectable
Inheritance
object
Object
Component
Behaviour
MonoBehaviour
UIBehaviour
Selectable
MultipleGraphicsSelectable
Implements
Derived

Examples

Button: quickly add a ColorableGraphic with explicit colors and timings:

using UnityEngine;
using UnityEngine.UI;
using Fallencake.UI;

public class MyCustomButton : Button
{
    [SerializeField] private Graphic _titleGraphic;

    protected override void Start()
    {
        base.Start();
        SelectableTransition = SelectableTransition.ColorTint;

        // Add color-tint target with explicit state colors, multiplier and fade
        AddColorableGraphic(
            target: _titleGraphic,
            normal: Color.white,
            highlighted: new Color(0.95f, 0.95f, 1f, 1f),
            pressed: new Color(0.85f, 0.85f, 0.95f, 1f),
            selected: new Color(0.95f, 0.95f, 1f, 1f),
            disabled: new Color(1f, 1f, 1f, 0.5f),
            colorMultiplier: 1.0f,
            fadeDuration: 0.1f);
    }
}

Slider: configure CanvasGroup-based fading via method:

using UnityEngine;
using UnityEngine.UI;
using Fallencake.UI;

public class MyVolumeSlider : Slider
{
    [SerializeField] private CanvasGroup _normal;
    [SerializeField] private CanvasGroup _highlighted;
    [SerializeField] private CanvasGroup _pressed;
    [SerializeField] private CanvasGroup _selected;
    [SerializeField] private CanvasGroup _disabled;

    protected override void Start()
    {
        base.Start();
        SelectableTransition = SelectableTransition.CanvasGroupFading;

        // Assign groups and fade duration
        SetFadingCanvasGroups(_normal, _highlighted, _pressed, _selected, _disabled, fadeDuration: 0.15f);
    }
}

Remarks

Uses Unity's UnityEngine.UI.Selectable state machine and extends it to control collections of colorable graphics, swappable sprites, and a CanvasGroup fading setup. Derived classes can customize behavior by adjusting SelectableTransition and editing the collections.

Fields

_colorableGraphics

[SerializeField]
protected List<ColorableGraphic> _colorableGraphics

Field Value

List<ColorableGraphic>

_swappableCanvasGroupe

[SerializeField]
protected SwappableCanvasGroup _swappableCanvasGroupe

Field Value

SwappableCanvasGroup

_swappableGraphics

[SerializeField]
protected List<SwappableSprite> _swappableGraphics

Field Value

List<SwappableSprite>

_transition

[SerializeField]
protected SelectableTransition _transition

Field Value

SelectableTransition

_tweenCoroutine

protected Coroutine _tweenCoroutine

Field Value

Coroutine

Properties

ColorableGraphics

Collection of graphic elements that can be color-tinted during button state transitions.

public List<ColorableGraphic> ColorableGraphics { get; set; }

Property Value

List<ColorableGraphic>

SelectableTransition

The type of transition that will be applied to the targetGraphic when the state changes.

public SelectableTransition SelectableTransition { get; set; }

Property Value

SelectableTransition

SwappableCanvasGroupe

Settings for CanvasGroups that can be swapped during button state transitions.

public SwappableCanvasGroup SwappableCanvasGroupe { get; set; }

Property Value

SwappableCanvasGroup

SwappableGraphics

Collection of graphic elements that can be swapped during button state transitions.

public List<SwappableSprite> SwappableGraphics { get; set; }

Property Value

List<SwappableSprite>

Methods

AddColorableGraphic(Graphic, SelectionColorBlock)

Creates and adds a ColorableGraphic configured with a target and color block.

public ColorableGraphic AddColorableGraphic(Graphic target, SelectionColorBlock colors)

Parameters

target Graphic

The UnityEngine.UI.Graphic to be color-tinted on state changes.

colors SelectionColorBlock

The SelectionColorBlock defining colors and timings.

Returns

ColorableGraphic

The created ColorableGraphic.

AddColorableGraphic(Graphic, Color, Color, Color, Color, Color, float, float)

Creates and adds a ColorableGraphic using explicit state colors.

public ColorableGraphic AddColorableGraphic(Graphic target, Color normal, Color highlighted, Color pressed, Color selected, Color disabled, float colorMultiplier = 1, float fadeDuration = 0.1)

Parameters

target Graphic

The UnityEngine.UI.Graphic to be color-tinted.

normal Color

Color for Normal state.

highlighted Color

Color for Highlighted state.

pressed Color

Color for Pressed state.

selected Color

Color for Selected state.

disabled Color

Color for Disabled state.

colorMultiplier float

Multiplier applied to colors.

fadeDuration float

Color transition duration in seconds.

Returns

ColorableGraphic

The created ColorableGraphic.

AddNewColorableGraphics()

Adds a new ColorableGraphic to the list of colorable graphics. This method is used when you need to dynamically add new UI elements that should change color based on button state. Typically called from the Unity Editor when configuring button appearance or programmatically when adding new colorable elements at runtime.

[Obsolete("Use AddColorableGraphic(Graphic, SelectionColorBlock) or the color overload instead.")]
public void AddNewColorableGraphics()

AddNewSwappableSprite()

Adds a new SwappableSprite to the list of swappable sprites. This method is used when you need to dynamically add new UI elements that should change sprite based on button state. Typically called from the Unity Editor when configuring button appearance or programmatically when adding new swappable elements at runtime.

[Obsolete("Use AddSwappableSprite(Graphic, SelectionSpriteState) or the sprite overload instead.")]
public void AddNewSwappableSprite()

AddSwappableSprite(Graphic, SelectionSpriteState)

Creates and adds a SwappableSprite configured with a target and sprite state.

public SwappableSprite AddSwappableSprite(Graphic target, SelectionSpriteState spriteState)

Parameters

target Graphic

The UnityEngine.UI.Graphic whose sprite will be swapped.

spriteState SelectionSpriteState

The SelectionSpriteState defining sprites per state.

Returns

SwappableSprite

The created SwappableSprite.

AddSwappableSprite(Image, Sprite, Sprite, Sprite, Sprite)

Creates and adds a SwappableSprite using explicit state sprites.

public SwappableSprite AddSwappableSprite(Image targetImage, Sprite highlighted, Sprite pressed, Sprite selected, Sprite disabled)

Parameters

targetImage Image

The UnityEngine.UI.Image to receive swapped sprites.

highlighted Sprite

Sprite for Highlighted state.

pressed Sprite

Sprite for Pressed state.

selected Sprite

Sprite for Selected state.

disabled Sprite

Sprite for Disabled state.

Returns

SwappableSprite

The created SwappableSprite.

DoStateTransition(SelectionState, bool)

Transition the Selectable to the entered state.

protected override void DoStateTransition(Selectable.SelectionState state, bool instant)

Parameters

state Selectable.SelectionState

State to transition to

instant bool

Should the transition occur instantly.

OnDestroy()

protected override void OnDestroy()

OnDisable()

protected override void OnDisable()

SetFadingCanvasGroups(CanvasGroup, CanvasGroup, CanvasGroup, CanvasGroup, CanvasGroup, float)

Configures SwappableCanvasGroupe with CanvasGroups per state and fade duration.

public void SetFadingCanvasGroups(CanvasGroup normal, CanvasGroup highlighted, CanvasGroup pressed, CanvasGroup selected, CanvasGroup disabled, float fadeDuration = 0.1)

Parameters

normal CanvasGroup

CanvasGroup for Normal state.

highlighted CanvasGroup

CanvasGroup for Highlighted state.

pressed CanvasGroup

CanvasGroup for Pressed state.

selected CanvasGroup

CanvasGroup for Selected state.

disabled CanvasGroup

CanvasGroup for Disabled state.

fadeDuration float

Alpha fade duration in seconds.

Start()

protected override void Start()