public static void SetValueForThreePartBar(UISprite[] parts, float value)
{
int totalWidth = parts[0].width + parts[1].width + parts[2].width;
int valueWidth = Mathf.RoundToInt(value * totalWidth);
if (valueWidth > totalWidth)
{
valueWidth = totalWidth;
}
if (valueWidth < 1)
{
// Don't show anything
parts[0].fillAmount = 0.0f;
parts[1].fillAmount = 0.0f;
parts[2].fillAmount = 0.0f;
}
else if (valueWidth <= parts[0].width)
{
// Show only first part
parts[0].fillAmount = (float)(valueWidth) / (float)parts[0].width;
parts[1].fillAmount = 0.0f;
parts[2].fillAmount = 0.0f;
}
else if (valueWidth <= (parts[0].width + parts[1].width))
{
// Show first and second part
parts[0].fillAmount = 1.0f;
parts[1].fillAmount = (float)(valueWidth - parts[0].width) / (float)(parts[1].width);
parts[2].fillAmount = 0.0f;
}
else
{
// Show all three parts
parts[0].fillAmount = 1.0f;
parts[1].fillAmount = 1.0f;
parts[2].fillAmount = (float)(valueWidth - parts[0].width - parts[1].width) / (float)(parts[2].width);
}
}