Description
The Clamped
property of the RangeAttribute
class indicates whether the value should be clamped within the specified range. When set to true
, any value assigned to the property will be automatically adjusted to stay within the defined Min
and Max
bounds.
Usage
Use the Clamped
property when you want to ensure that a value does not exceed the specified range limits. This is particularly useful in scenarios where user input needs to be constrained to a valid range, such as in UI sliders or input fields.
Example
// Example of using RangeAttribute with Clamped property
public class ExampleComponent : Component
{
[Range(0.0f, 10.0f, Clamped = true)]
public float ClampedValue { get; set; }
public ExampleComponent()
{
// Attempting to set ClampedValue to 15.0f will result in it being clamped to 10.0f
ClampedValue = 15.0f;
}
}