SaveIndicator
SaveIndicator is the auto save sign of a game: a small icon that spins or pulses while a save runs, a check when the save is done, and an error mark with a Retry button when it fails. An optional text says "Saving…", "Saved" or the message of the failure. A fast save still shows for a minimum time, and the indicator fades out after the check. Use it in a corner of the screen for checkpoints, for a settings change that saves at once, or for a cloud save.


Demo scene: SaveIndicatorDemo.unity.
How to add an indicator:
<tb:SaveIndicator name="save" class="save-corner" />
<!-- A disk that pulses, no text, and a check that stays until the next
save -->
<tb:SaveIndicator
name="cloud"
motion="Pulse"
show-text="false"
saved-time="0" />
The indicator is hidden while no save runs. Place it with USS, for example at the bottom right of the screen:
.save-corner {
position: absolute;
right: 24px;
bottom: 24px;
}
How to show a save from code:
var save = root.Q<SaveIndicator>("save");
save.Begin(); // the icon spins with "Saving…"
WriteSaveFile();
// the check and "Saved", then a fade out
save.Complete();
// the error mark, the message and Retry
save.Fail("Disk full");
save.Retried += () => SaveGame(); // a click on Retry
How to show a save that runs as a task. Track calls Begin, then Complete when the task ends or Fail when it throws:
// A task that runs already
bool saved = await save.Track(File.WriteAllTextAsync(path, json));
// A save to run: when it fails, the Retry button runs it again
await save.Track(() => cloud.UploadAsync(slot));
| Member | Description |
|---|---|
Begin() |
Shows that a save starts: the icon spins or pulses, with the saving text. Each Begin waits for its own Complete or Fail, so two saves at once show until both end. |
Complete() |
Shows that a save is done. The check shows when the last open save ends and the save has shown for MinShowTime. With no save open, the check shows at once, for a save that took no time. A failure stays. |
Fail(message) |
Shows that a save failed: the error mark, the message (or FailedText when it is empty) and the Retry button. The failure stays until the next Begin, a retry or Hide. |
Hide() |
Fades the indicator out from any state and forgets the open saves. |
Retry() |
Raises Retried, and runs the save of Track(Func<Task>) again when it failed. The Retry button calls it. |
Track(task) |
Shows the save that a task runs: Begin now, then Complete when the task ends, or Fail when it throws or is canceled. Returns true when the save is done. |
Track(save) |
Runs a Func<Task> and shows it as Track(task) does. When it fails, the Retry button runs it again. |
Motion (motion) |
How the icon moves while a save runs: Spin, a quarter arc that goes around a ring, or Pulse, a disk that fades in and out. Default Spin. The type is SaveIndicatorMotion. |
Icon (icon) |
A picture that replaces the ring or the disk while a save runs, such as the logo of the game. It turns with Spin and fades in and out with Pulse. The check and the error mark stay drawn. |
IconAnimation (icon-animation), IconAnimationClip (icon-animation-clip) |
A SpriteSheet that plays in place of the ring or the disk while a save runs, such as a spinning coin, and the clip that plays. It wins over Icon and Motion. The check and the error mark stay drawn. None (the default) keeps the drawn icon. IconAnimationElement is its AnimatedImage. |
ShowText (show-text) |
Shows the text next to the icon. Off, only the icon shows. On by default. |
SavingText (saving-text), SavedText (saved-text), FailedText (failed-text) |
The texts of the states. Empty shows the texts of ToolboxText: "Saving…", "Saved" and "Save failed". A message of Fail shows in place of FailedText. |
MinShowTime (min-show-time) |
The shortest time in milliseconds that a save shows before the check, so a fast save still shows. Default 1000. |
SavedTime (saved-time) |
The milliseconds that the check shows before the fade out. 0 keeps the check until the next save or Hide. Default 1500. |
FadeTime (fade-time) |
The milliseconds of the fade in and the fade out. 0 shows and hides the indicator at once. Default 300. |
ShowRetry (show-retry) |
Shows a Retry button with a failure. On by default. |
State |
What the indicator shows: Idle, Saving, Saved or Failed. The type is SaveIndicatorState. |
StateChanged |
The state changed. The handler gets the new state. |
Retried |
Raised by Retry, for a click on the Retry button. Save again from it, unless the save came from Track(Func<Task>): that save runs again by itself. |
Text |
The text that shows now. |
Error |
The exception of the tracked task that failed, until the next save. Null otherwise. |
RetryButton |
The Retry button, to change its text or its style from code. |
The indicator takes no keyboard focus. It and its icon and text ignore the pointer, so it can sit over the game. Only the Retry button of a failure takes clicks.
MinShowTimecounts fromBegin. A save that ends sooner keeps the saving icon until the time is up, and then shows the check.- A
Beginwhile the check shows or fades starts a new save at once, and the indicator fades back in from where it is. - A
Completewith noBeginshows the check alone, for a save that you show after it is done. - A failure wins over the other saves that run at the same time: their
Completeleaves the failure on. - The tick of the indicator runs only while something moves: a save, the check, its hold and the fades. A failure that shows, a check that stays and a hidden indicator cost nothing per frame, and the moves allocate nothing.
- The texts are the keys
tb.saving,tb.savedandtb.save-failedofToolboxText, and the button istb.retry, so a language table can change them. - The UI Builder shows the indicator as a save that runs, so you can design its look. It does not move there.
Tips:
- Call
BeginandCompletearound the save of a checkpoint, an auto save or a settings change. The indicator shows each save forMinShowTime, so a save that takes a few milliseconds still reads. - For a save to a server, use
Track(() => UploadAsync()): a failure shows Retry, and Retry runs the upload again. - Use
saved-time="0"for a check that stays, for example in a settings screen that saves each change. - Give the indicator the logo of your game with
icon, and pickPulsefor a logo that should not turn.
Styling
| Class | Element |
|---|---|
tb-save-indicator |
The indicator: a row with the icon, the text and the Retry button, on a surface with a border. |
tb-save-indicator__icon |
The icon, 20 px. It draws in its USS color: the accent color while a save runs. |
tb-save-indicator__label |
The text. |
tb-save-indicator__retry |
The Retry button of a failure. |
tb-save-indicator--saving |
The indicator while a save runs. |
tb-save-indicator--saved |
The indicator while the check shows. The icon takes --tb-color-success. |
tb-save-indicator--failed |
The indicator while a failure shows. The icon takes --tb-color-danger. |
tb-save-indicator--picture |
The indicator while a save runs and Icon holds a picture. |
| Property | Description |
|---|---|
--tb-save-indicator-track |
The color of the ring under the spinning arc. Default --tb-color-border. A clear color, rgba(0, 0, 0, 0), shows the arc alone. |
A game look, with no surface and a larger icon:
.tb-save-indicator {
background-color: transparent;
border-width: 0;
}
.tb-save-indicator__icon {
width: 32px;
height: 32px;
color: rgb(255, 210, 90);
}
SVG: Icon is a Background. An SVG imported as a VectorImage works as well as a texture. See Pictures: PNG or SVG.