UI Toolbox logoUI Toolbox
Support

AutoClickButton

An AutoClickButton is a Button that clicks itself after Delay milliseconds, such as "Continue" on a result screen. A bar at the bottom fills while the time runs.

An Accept button that counts down from 5, next to a Decline buttonAn Accept button that counts down from 5, next to a Decline button

<tb:AutoClickButton text="Continue" delay="5000" />
var next = root.Q<AutoClickButton>();
next.clicked += LoadNextLevel;
next.RegisterCallback<PointerEnterEvent>(_ => next.Paused = true);
next.RegisterCallback<PointerLeaveEvent>(_ => next.Paused = false);
Member Description
Delay (delay) Milliseconds until the button clicks itself (3000).
Paused (paused) Stops the time while true. The bar keeps its place.
AutoStart (auto-start) True (the default): the count starts when the button first attaches to a panel. False: call Restart.
Restart(), Cancel() Starts the count again from 0, also after a click. Stops the count without a click.
DrainRate (drain-rate) The part of the progress that Drain takes away each second, for example 0.5 for a full bar in 2 seconds. Default 0.
Drain(), Continue() Stops the count without a click and lowers the progress by DrainRate each second until it is 0. With DrainRate 0, Drain is Cancel. Continue starts the count from the progress of now. After a click, Continue is Restart.
IsDraining True while Drain lowers the progress.
IsCounting, IsDone True while the time runs. True after a click, by the user or by the time, until Restart.
ClickedByTime True when the last click came from the time, false when the user was first.
Elapsed, Progress, SecondsLeft The counted seconds, the part of Delay that has gone (0 to 1), and the whole seconds left, for a "Continue (3)" text. After a click, Elapsed and Progress keep the time of the click.

Quick time events

The button is also a prompt with a time limit. ClickedByTime tells a hit from a miss, and Elapsed is the reaction time.

prompt.AutoStart = false;
prompt.Delay = 1500;
prompt.clicked += () =>
    status.text = prompt.ClickedByTime ? "Too slow"
        : $"Hit in {prompt.Elapsed:0.00} s";
prompt.Restart(); // shows the prompt and starts the time

For a hold, call Restart() on the press and Cancel() on the release. The click of the time is then the end of the hold. A ProgressRing can show Progress in place of the bar.

For a hold that does not start over, set DrainRate. Call Continue() on the press and Drain() on the release. An early release then lowers the progress slowly, and the next press goes on from the progress of that time.

<tb:AutoClickButton
    name="hold"
    auto-start="false"
    delay="1500"
    drain-rate="0.5" />
// The press goes on from the progress, the release drains it
hold.DrainRate = 0.5f;   // a full bar drains in 2 seconds
// On the press:   if (!hold.IsCounting) hold.Continue();
// On the release: if (hold.IsCounting) hold.Drain();

The InputDemo example scene has a timed press, a hold with a ring (reset on release, or drain slowly) and a fast tap, with a key look and a gamepad look. A hold that comes to its end and a full tap bar each send sparks from a ParticleLayer, once for each success. For the hold, ClickedByTime tells the end from the click of the user, so a click of the user sends none.

Styling

Class Element
tb-auto-click-button The button. It has the look of the MessageBox buttons. The sheet hides its overflow, so the bar stays inside the corners.
tb-auto-click-button__text The text of the button, a TextElement child. text reads and writes it.
tb-auto-click-button__progress The bar at the bottom, 3 px, in --tb-color-accent. The script sets its width.
tb-auto-click-button--done On the button after a click. The sheet hides the bar.

The AutoClickButtonDemo scene shows the Continue of a result screen, a party invite, a delete that the player can stop and a turn that ends by itself in a custom look.