Class HexIntAttribute
Attribute to display an integer or long property in the Unity Inspector as a hexadecimal string.
public sealed class HexIntAttribute : PropertyAttribute
Inheritance
Examples
This example displays the integer value as a hexadecimal string in the Unity Inspector, zero-padded to 4 digits:
// Serialized field that appears as "0x000F" in the Inspector if the value is 15.
[HexInt(4)]
public int memoryAddress = 15;
The value can be edited in the Inspector using a hex format like "0x00FF", and Unity will parse it back into the integer field. Invalid input will be interpreted as 0.
Remarks
You can optionally specify a number of digits to zero-pad the displayed hex value.
Constructors
HexIntAttribute(int)
Initializes a new instance of the HexIntAttribute class with optional digit padding.
public HexIntAttribute(int digits)
Parameters
| Name | Type | Description |
|---|---|---|
digits | int | The number of digits to zero-pad to. Must be non-negative. |
Exceptions
ArgumentOutOfRangeException — Thrown if digits is negative.
HexIntAttribute()
Initializes a new instance of the HexIntAttribute class with no digit padding.
public HexIntAttribute()
Fields
digits
The number of digits to zero-pad the hex value to. For example, 4 pads the value to "000F".
public int digits
Field Value
int