Unit Attribute

Allows for converting between units, and displaying a value in a more user-friendly unit.

// Kilogram unit. Change the display by right-clicking.
// Try entering '6 lb'.
public float Weight;

// Meters per second unit, displayed as kilometers per hour in the inspector.
// Try entering '15 mph'.
[Unit(Units.MetersPerSecond, Units.KilometersPerHour)]
public float Speed;

// Meters, displayed as centimeters for finer control.
[Unit(Units.Meter, Units.Centimeter)]
public float Distance;

// The speed value, shown as miles per hours. Excellent for debugging values in the inspector.
[ShowInInspector, Unit(Units.MetersPerSecond, Units.MilesPerHour, DisplayAsString = true, ForceDisplayUnit = true)]
public float SpeedMilesPerHour => Speed;

// Add custom units. (Disabled to not add custom units to your project)
//public static void AddCustomUnit()
//    UnitNumberUtility.AddCustomUnit(
//      name: "Odin",
//      symbols: new string[] { "odin" },
//      unitCategory: UnitCategory.Distance,
//      multiplier: 1m / 42m);

// Use the custom unit by referencing it by name.
//[Unit(Units.Meter, "Odin")]
//public float Odins;