Class MinMaxRangeAttribute
Displays a Vector2 or Vector2Int serialized field as an interactive
dual-handle min-max range slider in the Unity Inspector.
Inherited Members
Namespace: Scylla.Core.Attributes
Assembly: ScyllaCore.dll
Syntax
[AttributeUsage(AttributeTargets.Field)]
public sealed class MinMaxRangeAttribute : PropertyAttribute
Remarks
The X component of the vector is treated as the lower bound (minimum) and the Y component is treated as the upper bound (maximum) of the selected range. Both handles are constrained within the absolute bounds defined by Min and Max, and the lower handle is always kept at or below the upper handle.
This is useful for authoring random value ranges directly in the Inspector, such as spawn delays, damage variance, particle lifetimes, or any quantity that varies within a bounded interval.
When applied to a Vector2Int field, the slider values are still stored
as float internally during editing and converted to integers when the
property is saved. The integer constructor overload accepts int bounds
for convenience but stores them as float in Min and
Max.
public class Spawner : MonoBehaviour
{
/* Float range: slider allows selecting any delay between 0.5 and 10 seconds */
[MinMaxRange(0.5f, 10f)]
[SerializeField] private Vector2 _spawnDelay = new Vector2(1f, 3f);
/* Integer range: slider allows selecting between 1 and 100 enemies */
[MinMaxRange(1, 100)]
[SerializeField] private Vector2Int _enemyCount = new Vector2Int(5, 20);
public float GetRandomSpawnDelay()
{
return Random.Range(_spawnDelay.x, _spawnDelay.y);
}
public int GetRandomEnemyCount()
{
return Random.Range(_enemyCount.x, _enemyCount.y + 1);
}
}
Constructors
MinMaxRangeAttribute(int, int)
Creates a min-max range slider with integer bounds, stored internally as floating-point values.
Declaration
public MinMaxRangeAttribute(int min, int max)
Parameters
| Type | Name | Description |
|---|---|---|
| int | min | The absolute minimum value the lower range handle can reach. Must be less
than or equal to |
| int | max | The absolute maximum value the upper range handle can reach. Must be greater
than or equal to |
Remarks
This overload accepts integer parameters for convenience when working with
discrete ranges. The values are widened to float and stored in
Min and Max. Apply to a Vector2Int
field for integer-specific slider behavior.
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | Thrown if |
MinMaxRangeAttribute(float, float)
Creates a min-max range slider with the specified floating-point bounds.
Declaration
public MinMaxRangeAttribute(float min, float max)
Parameters
| Type | Name | Description |
|---|---|---|
| float | min | The absolute minimum value the lower range handle can reach. Must be less
than or equal to |
| float | max | The absolute maximum value the upper range handle can reach. Must be greater
than or equal to |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | Thrown if |
Properties
Max
Gets the absolute maximum allowed value for the upper handle of the range slider.
Declaration
public float Max { get; }
Property Value
| Type | Description |
|---|---|
| float | A |
Remarks
The Y component of the decorated vector field cannot be set above this value. Always strictly greater than or equal to Min.
Min
Gets the absolute minimum allowed value for the lower handle of the range slider.
Declaration
public float Min { get; }
Property Value
| Type | Description |
|---|---|
| float | A |
Remarks
The X component of the decorated vector field cannot be set below this value. Always strictly less than or equal to Max.