UI Toolbox logoUI Toolbox
Support

AbilitySlot

AbilitySlot is one slot of an action bar: an icon, a cooldown sweep with the seconds left, a charge count and a key. A press flashes the slot. A press during the cooldown gives it a short nudge. Use it alone, or let a Hotbar make a row of them.

Five ability slots: ready, cooling down, with charges, blocked and activeFive ability slots: ready, cooling down, with charges, blocked and active

Video tutorial: AbilitySlot and Hotbar. All videos: Video tutorials. Demo scene: AbilitySlotDemo.unity.

How to add a slot:

<tb:AbilitySlot
    name="fireball"
    keyboard-glyph="keyboard-q"
    shape="Circle" />

How to use it, with a cooldown:

var slot = root.Q<AbilitySlot>("fireball");
slot.Icon = Background.FromTexture2D(fireIcon);
slot.Activated += () =>
{
    CastFireball();
    slot.StartCooldown(6);
};
// From your input code:
slot.Press();

How to show the mana:

// gray, and a press is refused
slot.Usable = player.Mana >= FIREBALL_MANA;
Member Description
Icon (icon) The picture: a Texture2D or Sprite.
EmptyIcon (empty-icon) Shown dark when Icon is empty: what the slot takes.
Shape (shape) The mask of the icon (MaskShape). Default RoundedSquare. The sweep rounds its corners to match Circle and RoundedSquare.
KeyboardGlyph (keyboard-glyph) The key glyph at the top left: a PromptFont name such as keyboard-3, or any text. Empty hides it. The Hotbar sets it. The glyph is 20 px by default.
Charges (charges) The count at the bottom right.
MaxCharges (max-charges) The count shows when this is over 1, or when Charges is over 1.
Usable (usable) False grays the icon and refuses a press.
Active (active) A glowing border, for toggles and auras.
ShowSeconds (show-seconds) Shows the seconds left in the middle. Default true.
UnscaledTime (unscaled-time) The cooldown ignores Time.timeScale.
StartCooldown(seconds) Starts a cooldown. The same as SetCooldown(seconds, seconds).
SetCooldown(remaining, total) Starts a cooldown part way, for a load or a server value. A value of 0 or less, or NaN, clears the cooldown.
ClearCooldown() Ends the cooldown at once, with no flash and no CooldownFinished.
IsCoolingDown, CooldownRemaining, CooldownTotal, CooldownProgress The cooldown state. CooldownProgress is 1 when ready.
Press() Flashes and raises Activated. During a cooldown or when not usable, it plays a short nudge and returns false. A click or a submit calls it.
SwapWith(other) Swaps the icons, charges, cooldowns, Usable, Active, tooltips and userData of two slots. The keys stay.
ClearContents() Empties the slot. The empty icon and the key stay.
Activated The slot was pressed.
CooldownFinished The cooldown ran out; the slot flashes.

Tips:

In the examples

Styling

Class Element
tb-ability-slot The slot: 48 px wide and high.
tb-ability-slot__icon The icon (a MaskImage).
tb-ability-slot__sweep The dark cooldown sweep (a MaskImage).
tb-ability-slot__seconds The seconds left.
tb-ability-slot__charges The count.
tb-ability-slot__key The key (an InputGlyph).
tb-ability-slot--cooling During a cooldown.
tb-ability-slot--ready The flash at the end of a cooldown.
tb-ability-slot--pressed The flash of a press.
tb-ability-slot--denied The short nudge of a refused press.
tb-ability-slot--unusable Usable is false.
tb-ability-slot--active Active is true.
tb-ability-slot--empty No icon.
Variable Default Does
--tb-ability-sweep-color rgba(0, 0, 0, 0.6) The color of the sweep.
--tb-ability-empty-color rgba(0, 0, 0, 0.5) The tint of the empty icon.
.my-bar .tb-ability-slot {
    width: 64px;
    height: 64px;
    --tb-ability-sweep-color: rgba(20, 0, 40, 0.7);
}

.my-bar .tb-ability-slot__key {
    font-size: 16px;
}

The AbilitySlotDemo scene shows a skill whose cooldown a pause stops or not, a stack of potions whose last drink leaves an empty flask, an aura that a press turns on and off and that turns gray without mana, and the shape, the size, the sweep color and the key of the slot.

SVG: Icon is a Background. An SVG imported as a VectorImage works as well as a texture. See Pictures: PNG or SVG.