Skip to content

Toggle

namespace Griff.Scenes;
public sealed class Toggle : Component

Turns a Button into a switch: each click flips IsOn, and its label can say which way it’s set (“Sound: On”). Set Setting to turn the sound or fullscreen on and off with no code, remembered next time. Needs a Button on the same entity.

This is a component: its saved properties are on its component page.

public bool IsOn { get; set; }

Whether it’s on now; each click flips it.

public string? OffText { get; set; }

What the entity’s Text says while it’s off, e.g. “Sound: Off”.

public string? OnText { get; set; }

What the entity’s Text says while it’s on, e.g. “Sound: On”. Empty leaves the text alone.

public string? SaveAs { get; set; }

A name to keep it under in Game.SaveData, e.g. “screenShake”; read it with GetBool.

public GameSetting Setting { get; set; }

A setting of the game it switches: Sound, Fullscreen or VSync. While set, the toggle always shows that setting.

public event Action<Toggle>? Changed

Raised when the player flips it.