Namespace: | Sirenix.OdinInspector |
Assembly: | Sirenix.OdinInspector.Attributes |
[AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Module | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum | AttributeTargets.Constructor | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Interface | AttributeTargets.Parameter | AttributeTargets.Delegate | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter | AttributeTargets.All, AllowMultiple = false, Inherited = true)]
[Conditional("UNITY_EDITOR")]
public sealed class MaxValueAttribute : Attribute, _Attribute
MaxValue is used on primitive fields. It caps value of the field to a maximum value.
Use this to define a maximum value for the field.
Note that this attribute only works in the editor! Values changed from scripting will not be capped at a maximum.
The following example shows a component where a speed value must be less than or equal to 200.
public class Car : MonoBehaviour
{
// The speed of the car must be less than or equal to 200.
[MaxValue(200)]
public float Speed;
}
The following example shows how MaxValue can be combined with MinValueAttribute.
public class Health : MonoBehaviour
{
// The speed value must be between 0 and 200.
[MinValue(0), MaxValue(200)]
public float Speed;
}
public MaxValueAttribute(double maxValue)
System.Double | maxValue | The max value. |
public MaxValueAttribute(string expression)
System.String | expression | The string with which to resolve a maximum value. This could be a field, property or method name, or an expression. |
public string Expression
public double MaxValue