Class CreditsPill
A titlebar badge showing an AI credit balance.
Implements
Inherited Members
Namespace: Unity.AppUI.UI
Assembly: Unity.AppUI.dll
Syntax
[UxmlElement]
public class CreditsPill : BaseVisualElement, IEventHandler, IResolvedStyle, ITransform, ITransitionAnimations, IExperimentalFeatures, IVisualElementScheduler, IContextOverrideElement, IAdditionalDataHolder
Remarks
The number is shown compactly, for instance "51k Credits", with the exact figure in the tooltip. loading swaps it for a LoadingDots while the balance is being fetched, and error swaps it for a warning glyph with errorMessage as the tooltip. Loading wins over error: there is nothing to report about a request that has not finished.
tooltipLabel replaces the exact-balance tooltip, as the registry's tooltip
prop does, and a balance update leaves it alone.
Examples
A resolved balance.
var pill = new CreditsPill { credits = 51200 };
parentElement.Add(pill);
The two unresolved states, in UXML.
<appui:CreditsPill loading="true" />
<appui:CreditsPill error="true" />
Constructors
CreditsPill()
Default constructor.
Declaration
public CreditsPill()
Fields
defaultErrorMessage
The default explanation shown when the balance could not be fetched.
Declaration
public const string defaultErrorMessage = "Couldn't load your credit balance. Check your connection."
Field Value
| Type | Description |
|---|---|
| string |
defaultLabel
The default trailing label.
Declaration
public const string defaultLabel = "Credits"
Field Value
| Type | Description |
|---|---|
| string |
dotsUssClassName
The styling class of the loading dots.
Declaration
public const string dotsUssClassName = "appui-credits-pill__dots"
Field Value
| Type | Description |
|---|---|
| string |
iconUssClassName
The styling class of the leading glyph.
Declaration
public const string iconUssClassName = "appui-credits-pill__icon"
Field Value
| Type | Description |
|---|---|
| string |
ussClassName
The CreditsPill main styling class.
Declaration
public const string ussClassName = "appui-credits-pill"
Field Value
| Type | Description |
|---|---|
| string |
valueUssClassName
The styling class of the balance text.
Declaration
public const string valueUssClassName = "appui-credits-pill__value"
Field Value
| Type | Description |
|---|---|
| string |
warningUssClassName
The styling class of the warning glyph.
Declaration
public const string warningUssClassName = "appui-credits-pill__warning"
Field Value
| Type | Description |
|---|---|
| string |
Properties
credits
The credit balance.
Declaration
[CreateProperty]
[UxmlAttribute]
public float credits { get; set; }
Property Value
| Type | Description |
|---|---|
| float |
error
Whether the balance could not be fetched.
Declaration
[CreateProperty]
[UxmlAttribute]
public bool error { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
errorMessage
Why the balance could not be fetched. Shown as the tooltip while error is set.
Declaration
[CreateProperty]
[UxmlAttribute]
public string errorMessage { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
icon
The leading glyph. Retarget its iconName to front the pill with something other than the sparkle.
Declaration
public Icon icon { get; }
Property Value
| Type | Description |
|---|---|
| Icon |
label
The trailing label after the number. "Credits" by default.
Declaration
[CreateProperty]
[UxmlAttribute]
public string label { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
loading
Whether the balance is still being fetched. Takes precedence over error.
Declaration
[CreateProperty]
[UxmlAttribute]
public bool loading { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
prefix
An optional prefix glued to the number, for instance "+".
Declaration
[CreateProperty]
[UxmlAttribute]
public string prefix { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
tooltipLabel
Replaces the exact-balance tooltip while the balance is shown. Null or empty, the default, shows the exact balance.
Declaration
[CreateProperty]
[UxmlAttribute]
public string tooltipLabel { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
Remarks
The registry's tooltip prop. It cannot be named tooltip here, since that is
tooltip, which the pill writes on every refresh; it is named
after tooltipLabel, its sibling's override.
The registry's precedence holds: the error message still takes its place while error is set, and loading shows no tooltip at all. A value written straight to tooltip is not lost either: the next refresh adopts it here rather than writing over it.