NaughtyAttributes
NaughtyAttributes copied to clipboard
[Request] "High" value and colours for Progress Bar
It would be handy if there was a way to add a high value for progress bars at which point it'd change its colour:
[ProgressBar("Stamina", "maxStamina", EColor.Green, "highStamina", EColor.Yellow)]
public int stamina = 50;
public int highStamina = 150;
public int maxStamina = 200;
In this example, above 150, the bar would change colour to yellow. Additionally, it'd be great if there was an option to add a third colour for when the bar's value matches max value:
[ProgressBar("Stamina", "maxStamina", EColor.Green, "highStamina", EColor.Yellow, EColor.Red)]
In this example, if stamina reaches 200, the bar becomes red from yellow.
Thank you for your consideration and thank you for making NaughtyAttributes
Here if you dont mind to have a try:
[ProgressBar(0, nameof(maxStamina), colorCallback: nameof(StaminaColor), titleCallback: nameof(StaminaTitle))]
[RichLabel(null)]
public int stamina = 50;
public int highStamina = 150;
public int maxStamina = 200;
private Color StaminaColor()
{
if (stamina < highStamina)
{
return Color.red;
}
return Color.Lerp(Color.yellow, Color.green, Mathf.InverseLerp(highStamina, maxStamina, stamina));
}
private string StaminaTitle(float curValue, float min, float max, string label) => $"[{label}] {curValue / max:P}";