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
-
objectObjectComponentBehaviourMonoBehaviourUIBehaviourSelectableMultipleGraphicsSelectable
- 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
_swappableGraphics
[SerializeField]
protected List<SwappableSprite> _swappableGraphics
Field Value
- List<SwappableSprite>
_transition
[SerializeField]
protected SelectableTransition _transition
Field Value
_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
SwappableCanvasGroupe
Settings for CanvasGroups that can be swapped during button state transitions.
public SwappableCanvasGroup SwappableCanvasGroupe { get; set; }
Property Value
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
targetGraphicThe UnityEngine.UI.Graphic to be color-tinted on state changes.
colorsSelectionColorBlockThe 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
targetGraphicThe UnityEngine.UI.Graphic to be color-tinted.
normalColorColor for Normal state.
highlightedColorColor for Highlighted state.
pressedColorColor for Pressed state.
selectedColorColor for Selected state.
disabledColorColor for Disabled state.
colorMultiplierfloatMultiplier applied to colors.
fadeDurationfloatColor 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
targetGraphicThe UnityEngine.UI.Graphic whose sprite will be swapped.
spriteStateSelectionSpriteStateThe 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
targetImageImageThe UnityEngine.UI.Image to receive swapped sprites.
highlightedSpriteSprite for Highlighted state.
pressedSpriteSprite for Pressed state.
selectedSpriteSprite for Selected state.
disabledSpriteSprite 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
stateSelectable.SelectionStateState to transition to
instantboolShould 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
normalCanvasGroupCanvasGroup for Normal state.
highlightedCanvasGroupCanvasGroup for Highlighted state.
pressedCanvasGroupCanvasGroup for Pressed state.
selectedCanvasGroupCanvasGroup for Selected state.
disabledCanvasGroupCanvasGroup for Disabled state.
fadeDurationfloatAlpha fade duration in seconds.
Start()
protected override void Start()