Table of Contents

Class ModularToggle

Namespace
Fallencake.UI
Assembly
Fallencake.UI.dll

A modular toggle consisting of several graphic elements, like changeable background and handle.

[AddComponentMenu("Modular UI/Modular Toggle", 32)]
public class ModularToggle : ToggleBase, IMultiSelectable, ISaveable, IToggleAudioProvider, IAudioProvider
Inheritance
object
Object
Component
Behaviour
MonoBehaviour
UIBehaviour
Selectable
ModularToggle
Implements
Inherited Members

Properties

AudioSource

AudioSource used to play sounds.

public AudioSource AudioSource { get; set; }

Property Value

AudioSource

Component

"The MonoBehaviour component used to run coroutines or for attaching the Animator component."

public MonoBehaviour Component { get; }

Property Value

MonoBehaviour

DeselectSound

Sound played on deselect.

public AudioData DeselectSound { get; }

Property Value

AudioData

EnableSounds

Enables/disables sound playback for this component.

public bool EnableSounds { get; set; }

Property Value

bool

EnableSwitchText

public bool EnableSwitchText { get; set; }

Property Value

bool

IsColorableText

public bool IsColorableText { get; }

Property Value

bool

IsFadingView

public bool IsFadingView { get; set; }

Property Value

bool

IsStretchingHandle

public bool IsStretchingHandle { get; }

Property Value

bool

PressSound

Sound played on press/submit.

public AudioData PressSound { get; }

Property Value

AudioData

SelectSound

Sound played on select/hover.

public AudioData SelectSound { get; }

Property Value

AudioData

Selectable

"The selectable component of the toggle. Used to select the toggle and handle navigation events."

public Selectable Selectable { get; }

Property Value

Selectable

SoundSource

public AudioSource SoundSource { get; set; }

Property Value

AudioSource

SwitchDirection

The axis along which the handle moves. Updates handle anchors/pivot to edge-centered positions.

public SwitchDirection SwitchDirection { get; set; }

Property Value

SwitchDirection

ToggleOffSound

Sound when toggled off.

public AudioData ToggleOffSound { get; }

Property Value

AudioData

ToggleOnSound

Sound when toggled on.

public AudioData ToggleOnSound { get; }

Property Value

AudioData

TweenAnimator

public ToggleTweenAnimator TweenAnimator { get; set; }

Property Value

ToggleTweenAnimator

Volume

Per-component volume multiplier.

public float Volume { get; set; }

Property Value

float

interactable

Controls whether the toggle can be interacted with. When false, the toggle will not respond to user input. Updates the audio handler's triggers based on the current interactable state and sound settings.

public bool interactable { get; set; }

Property Value

bool

Methods

ApplyHandleAnchorsForDirection()

Applies anchors and pivot to the handle based on current SwitchDirection and IsOn. Keeps the handle centered on the corresponding edge.

public void ApplyHandleAnchorsForDirection()

Awake()

Convenience function to get the Animator component on the GameObject.

protected override void Awake()

Examples

using UnityEngine;
using System.Collections;
using UnityEngine.UI; // Required when Using UI elements.

public class ExampleClass : MonoBehaviour
{
    private Animator buttonAnimator;
    public Button button;

    void Start()
    {
        //Assigns the "buttonAnimator" with the button's animator.
        buttonAnimator = button.animator;
    }
}

InstantSwitch(bool)

Instantly update visuals of handle/background.

protected override void InstantSwitch(bool isOn)

Parameters

isOn bool

OnDestroy()

protected override void OnDestroy()

OnPointerClick(PointerEventData)

Handle pointer click to toggle value when interactable.

public override void OnPointerClick(PointerEventData eventData)

Parameters

eventData PointerEventData

OnPointerEnter(PointerEventData)

Evaluate current state and transition to appropriate state. New state could be pressed or hover depending on pressed state.

public override void OnPointerEnter(PointerEventData eventData)

Parameters

eventData PointerEventData

Examples

using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.EventSystems;// Required when using Event data.

public class ExampleClass : MonoBehaviour, IPointerEnterHandler// required interface when using the OnPointerEnter method.
{
    //Do this when the cursor enters the rect area of this selectable UI object.
    public void OnPointerEnter(PointerEventData eventData)
    {
        Debug.Log("The cursor entered the selectable UI element.");
    }
}

OnPointerExit(PointerEventData)

Evaluate current state and transition to normal state.

public override void OnPointerExit(PointerEventData eventData)

Parameters

eventData PointerEventData

Examples

using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.EventSystems;// Required when using Event data.

public class ExampleClass : MonoBehaviour, IPointerExitHandler// required interface when using the OnPointerExit method.
{
    //Do this when the cursor exits the rect area of this selectable UI object.
    public void OnPointerExit(PointerEventData eventData)
    {
        Debug.Log("The cursor exited the selectable UI element.");
    }
}

PlayOnDeselectSound()

public void PlayOnDeselectSound()

PlayOnHoveredSound()

public void PlayOnHoveredSound()

PlayOnPressedSound()

public void PlayOnPressedSound()

PlaySwitchTween(bool)

Play animated transition between states. Override in derived controls.

protected override void PlaySwitchTween(bool isOn)

Parameters

isOn bool

SetActiveTextLabels(bool)

public void SetActiveTextLabels(bool isActive)

Parameters

isActive bool