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 ProgressBarAttribute : Attribute, _Attribute
Draws a horizontal progress bar based on the value of the property.
Use it for displaying a meter to indicate how full an inventory is, or to make a visual indication of a health bar.
The following example shows how ProgressBar can be used.
public class ProgressBarExample : MonoBehaviour
{
// Default progress bar.
[ProgressBar(0, 100)]
public int ProgressBar;
// Health bar.
[ProgressBar(0, 100, ColorMember = "GetHealthBarColor")]
public float HealthBar = 50;
private Color GetHealthBarColor(float value)
{
// Blends between red, and yellow color for when the health is below 30,
// and blends between yellow and green color for when the health is above 30.
return Color.Lerp(Color.Lerp(
Color.red, Color.yellow, MathUtilities.LinearStep(0f, 30f, value)),
Color.green, MathUtilities.LinearStep(0f, 100f, value));
}
// Stacked health bar.
// The ProgressBar attribute is placed on property, without a set method, so it can't be edited directly.
// So instead we have this Range attribute on a float to change the value.
[Range(0, 300)]
public float StackedHealth;
[ProgressBar(0, 100, ColorMember = "GetStackedHealthColor", BackgroundColorMember = "GetStackHealthBackgroundColor")]
private float StackedHealthProgressBar
{
// Loops the stacked health value between 0, and 100.
get { return this.StackedHealth - 100 * (int)((this.StackedHealth - 1) / 100); }
}
private Color GetStackedHealthColor()
{
return
this.StackedHealth > 200 ? Color.cyan :
this.StackedHealth > 100 ? Color.green :
Color.red;
}
private Color GetStackHealthBackgroundColor()
{
return
this.StackedHealth > 200 ? Color.green :
this.StackedHealth > 100 ? Color.red :
new Color(0.16f, 0.16f, 0.16f, 1f);
}
// Custom color and height.
[ProgressBar(-100, 100, r: 1, g: 1, b: 1, Height = 30)]
public short BigProgressBar = 50;
// You can also reference members by name to dynamically assign the min and max progress bar values.
[ProgressBar("DynamicMin", "DynamicMax")]
public float DynamicProgressBar;
public float DynamicMin, DynamicMax;
}
public ProgressBarAttribute(double min, double max, float r = 0.15F, float g = 0.47F, float b = 0.74F)
System.Double | min | The minimum value. |
System.Double | max | The maximum value. |
System.Single | r | The red channel of the color of the progress bar. |
System.Single | g | The green channel of the color of the progress bar. |
System.Single | b | The blue channel of the color of the progress bar. |
public ProgressBarAttribute(double min, string maxGetter, float r = 0.15F, float g = 0.47F, float b = 0.74F)
System.Double | min | The minimum value. |
System.String | maxGetter | A resolved string that should evaluate to a float value, and will be used as the max bounds. |
System.Single | r | The red channel of the color of the progress bar. |
System.Single | g | The green channel of the color of the progress bar. |
System.Single | b | The blue channel of the color of the progress bar. |
public ProgressBarAttribute(string minGetter, double max, float r = 0.15F, float g = 0.47F, float b = 0.74F)
System.String | minGetter | A resolved string that should evaluate to a float value, and will be used as the min bounds. |
System.Double | max | The maximum value. |
System.Single | r | The red channel of the color of the progress bar. |
System.Single | g | The green channel of the color of the progress bar. |
System.Single | b | The blue channel of the color of the progress bar. |
public ProgressBarAttribute(string minGetter, string maxGetter, float r = 0.15F, float g = 0.47F, float b = 0.74F)
System.String | minGetter | A resolved string that should evaluate to a float value, and will be used as the min bounds. |
System.String | maxGetter | A resolved string that should evaluate to a float value, and will be used as the max bounds. |
System.Single | r | The red channel of the color of the progress bar. |
System.Single | g | The green channel of the color of the progress bar. |
System.Single | b | The blue channel of the color of the progress bar. |
public float B
public string BackgroundColorGetter
public string ColorGetter
public string CustomValueStringGetter
public float G
public int Height
public double Max
public string MaxGetter
public double Min
public string MinGetter
public float R
true
then the progress bar will be drawn in tiles.
public bool Segmented
public Color Color { get; }
true
then there will be drawn a value label on top of the progress bar.
public bool DrawValueLabel { get; set; }
public bool DrawValueLabelHasValue { get; }
public TextAlignment ValueLabelAlignment { get; set; }
public bool ValueLabelAlignmentHasValue { get; }