Version 2.1.0.0

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)]
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 maxMember, float r = 0.15F, float g = 0.47F, float b = 0.74F)
Parameters
System.Double min

The minimum value.

System.String maxMember

The name of a field, property or method to get the max values from.

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 minMember, double max, float r = 0.15F, float g = 0.47F, float b = 0.74F)
Parameters
System.String minMember

The name of a field, property or method to get the min values from.

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 minMember, string maxMember, float r = 0.15F, float g = 0.47F, float b = 0.74F)
Parameters
System.String minMember

The name of a field, property or method to get the min values from.

System.String maxMember

The name of a field, property or method to get the max values from.

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
BackgroundColorMember
Optional reference to a Color field, property or method, to dynamically change the background color of the progress bar. Default background color is (0.16, 0.16, 0.16, 1).
public string BackgroundColorMember
ColorMember
Optional reference to a Color field, property or method, to dynamically change the color of the progress bar.
public string ColorMember
CustomValueStringMember
References a member by name to get a custom value label string from.
public string CustomValueStringMember
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
MaxMember
The name of a field, property or method to get the max values from.
public string MaxMember
Min
The minimum value.
public double Min
MinMember
The name of a field, property or method to get the min values from.
public string MinMember
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

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

This website is brand new and built with the Odin 2.1 beta in mind. This means you might discover some features such as attribute expressions that are only available in the beta.

You can download the 2.1 beta from here and read the patch-notes here.