NaughtyAttributes
NaughtyAttributes copied to clipboard
[Request] MinMaxValue to support dynamic variables
It would be really handy if one could specify min/max values from other existing variables, like with ProgressBars:
public class NaughtyComponent : MonoBehaviour {
[MinValue("minStamina"), MaxValue("maxStamina)"]
public int myInt;
public int minStamina;
public int maxStamina;
}
public class NaughtyComponent : MonoBehaviour {
[MinValue("minValue"), MaxValue("maxValue)"]
public float myFloat;
public float minValue;
public float maxValue;
}
This would reduce the checks one would need to do to make sure values remain within ranges that could dynamically change. Thank you
As this project hasn't merge PR for years, here is one and it is compatible to and can work together with NaughtyAttributes
I'll just paste the example:
public class MinMaxSliderExample: MonoBehaviour
{
[field: SerializeField, MinMaxSlider(-100f, 100f)]
public Vector2 OuterRange { get; private set; }
[SerializeField, MinMaxSlider(nameof(GetOuterMin), nameof(GetOuterMax), 1)] public Vector2Int _innerRange;
private float GetOuterMin() => OuterRange.x;
private float GetOuterMax() => OuterRange.y;
[field: SerializeField]
public float DynamicMin { get; private set; }
[field: SerializeField]
public float DynamicMax { get; private set; }
[SerializeField, MinMaxSlider(nameof(DynamicMin), nameof(DynamicMax))] private Vector2 _propRange;
[SerializeField, MinMaxSlider(nameof(DynamicMin), 100f)] private Vector2 _propLeftRange;
[SerializeField, MinMaxSlider(-100f, nameof(DynamicMax))] private Vector2 _propRightRange;
}