Skip to content

Game.UI.Widgets.NumberUnitAttribute

Assembly:

Namespace: Game.UI.Widgets

Type: public class NumberUnitAttribute

Base: UnityEngine.PropertyAttribute

Summary:
An attribute to annotate numeric fields or properties with a unit string (for example "km/h", "%", "m"). Primarily intended for use by UI code or custom property drawers to show a unit label next to a numeric value in editors or runtime UI. The attribute targets fields and properties.


Fields

  • None
    This class does not declare any custom backing fields; it only exposes a property.

Properties

  • public string Unit { get; set; }
    Holds the unit label to display alongside the number. Can be set through the constructor or assigned directly. Typical values: "km/h", "%", "m", "s", etc. UI code or property drawers can read this value to render the unit text.

Constructors

  • public NumberUnitAttribute(string unit)
    Creates a new NumberUnitAttribute and initializes the Unit property with the provided string. Use this to supply the unit text when applying the attribute.

Methods

  • None
    This attribute class does not define any methods beyond what it inherits from System.Attribute / UnityEngine.PropertyAttribute.

Usage Example

// Apply to a field
[NumberUnit("km/h")]
public float maxSpeed;

// Apply to a property
[NumberUnit("%")]
public float FillPercentage { get; set; }

// In a custom property drawer or UI renderer you would read the attribute:
// var attr = (NumberUnitAttribute)attribute;
// Draw the numeric field and then draw attr.Unit next to it.