Version 3.3.1.2

Odin has a dedicated attribute overview with examples

ProgressBarAttribute class

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.

Inheritance
  • System.Object
  • System.Attribute
  • ProgressBarAttribute
Example

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;
}

Constructors

ProgressBarAttribute(Double, Double, Single, Single, Single)
Draws a progress bar for the value.
public ProgressBarAttribute(double min, double max, float r = 0.15F, float g = 0.47F, float b = 0.74F)
Parameters
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.

ProgressBarAttribute(Double, String, Single, Single, Single)
Draws a progress bar for the value.
public ProgressBarAttribute(double min, string maxGetter, float r = 0.15F, float g = 0.47F, float b = 0.74F)
Parameters
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.

ProgressBarAttribute(String, Double, Single, Single, Single)
Draws a progress bar for the value.
public ProgressBarAttribute(string minGetter, double max, float r = 0.15F, float g = 0.47F, float b = 0.74F)
Parameters
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.

ProgressBarAttribute(String, String, Single, Single, Single)
Draws a progress bar for the value.
public ProgressBarAttribute(string minGetter, string maxGetter, float r = 0.15F, float g = 0.47F, float b = 0.74F)
Parameters
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.

Fields

B
The blue channel of the color of the progress bar.
public float B
BackgroundColorGetter
Optional resolved string that should evaluate to a Color value, to dynamically change the background color of the progress bar. Default background color is (0.16, 0.16, 0.16, 1). It supports a variety of color formats, including named colors (e.g. "red", "orange", "green", "blue"), hex codes (e.g. "#FF0000" and "#FF0000FF"), and RGBA (e.g. "RGBA(1,1,1,1)") or RGB (e.g. "RGB(1,1,1)"), including Odin attribute expressions (e.g "@this.MyColor"). Here are the available named colors: black, blue, clear, cyan, gray, green, grey, magenta, orange, purple, red, transparent, transparentBlack, transparentWhite, white, yellow, lightblue, lightcyan, lightgray, lightgreen, lightgrey, lightmagenta, lightorange, lightpurple, lightred, lightyellow, darkblue, darkcyan, darkgray, darkgreen, darkgrey, darkmagenta, darkorange, darkpurple, darkred, darkyellow.
public string BackgroundColorGetter
ColorGetter
Supports a variety of color formats, including named colors (e.g. "red", "orange", "green", "blue"), hex codes (e.g. "#FF0000" and "#FF0000FF"), and RGBA (e.g. "RGBA(1,1,1,1)") or RGB (e.g. "RGB(1,1,1)"), including Odin attribute expressions (e.g "@this.MyColor"). Here are the available named colors: black, blue, clear, cyan, gray, green, grey, magenta, orange, purple, red, transparent, transparentBlack, transparentWhite, white, yellow, lightblue, lightcyan, lightgray, lightgreen, lightgrey, lightmagenta, lightorange, lightpurple, lightred, lightyellow, darkblue, darkcyan, darkgray, darkgreen, darkgrey, darkmagenta, darkorange, darkpurple, darkred, darkyellow.
public string ColorGetter
CustomValueStringGetter
A resolved string to get a custom value label string from.
public string CustomValueStringGetter
G
The green channel of the color of the progress bar.
public float G
Height
The height of the progress bar in pixels. Defaults to 12 pixels.
public int Height
Max
The maximum value.
public double Max
MaxGetter
A resolved string that should evaluate to a float value, and will be used as the max bounds.
public string MaxGetter
Min
The minimum value.
public double Min
MinGetter
A resolved string that should evaluate to a float value, and will be used as the min bounds.
public string MinGetter
R
The red channel of the color of the progress bar.
public float R
Segmented
If true then the progress bar will be drawn in tiles.
public bool Segmented

Properties

Color
public Color Color { get; }
DrawValueLabel
If true then there will be drawn a value label on top of the progress bar.
public bool DrawValueLabel { get; set; }
DrawValueLabelHasValue
Gets a value indicating if the user has set a custom DrawValueLabel value.
public bool DrawValueLabelHasValue { get; }
ValueLabelAlignment
The alignment of the value label on top of the progress bar. Defaults to center.
public TextAlignment ValueLabelAlignment { get; set; }
ValueLabelAlignmentHasValue
Gets a value indicating if the user has set a custom ValueLabelAlignment value.
public bool ValueLabelAlignmentHasValue { get; }