Clamp Attribute
Attribute to clamp a numeric field between two values
- Parameters:
floatminValue: The min value to clampfloatmaxValue: The max value to clampfloatminValueX: The min value to clamp on XfloatmaxValueX: The max value to clamp on XfloatminValueY: The min value to clamp on YfloatmaxValueY: The max value to clamp on YfloatminValueZ: The min value to clamp on ZfloatmaxValueZ: The max value to clamp on ZfloatminValueW: The min value to clamp on WfloatmaxValueW: The max value to clamp on W
Example:
using UnityEngine;
using EditorAttributes;
public class AttributesExample : MonoBehaviour
{
[SerializeField, Clamp(-50, 50)] private int intField;
[SerializeField, Clamp(-5.5f, 5.5f)] private float floatField;
}
Now the values will be clamped between the min and max specified
By default on vectors the provided min and max will affect all axis, but you can also provide different min max values for different axis:
using UnityEngine;
using EditorAttributes;
public class AttributesExample : MonoBehaviour
{
[SerializeField, Clamp(-10f, 10f, -5f, 5f)] private Vector2 vector2Field;
[SerializeField, Clamp(-10f, 10f, -5f, 5f, -3.5f, 3.5f)] private Vector3 vector3Field;
}
Now the values of each axis will be clamped between the min and max specified for their axis