/// <summary> /// Lerps between 2 HSBColors over value t. /// </summary> /// <param name="a">The first HSBColor.</param> /// <param name="b">The second HSBColor.</param> /// <param name="t">The t value. Closer to 0 will result in a color closer to a, and a value closer to 1 will result in a color closer to b.</param> /// <returns>The lerped Color.</returns> public static HSBColor Lerp(HSBColor a, HSBColor b, float t) { float h, s; //check special case black (Color.b==0): interpolate neither hue nor saturation! //check special case grey (Color.s==0): don't interpolate hue! if (a.m_B == 0) { h = b.m_H; s = b.m_S; } else if (b.m_B == 0) { h = a.m_H; s = a.m_S; } else { if (a.m_S == 0) { h = b.m_H; } else if (b.m_S == 0) { h = a.m_H; } else { // works around bug with LerpAngle float angle = Mathf.LerpAngle(a.m_H * 360f, b.m_H * 360f, t); while (angle < 0f) { angle += 360f; } while (angle > 360f) { angle -= 360f; } h = angle / 360f; } s = Mathf.Lerp(a.m_S, b.m_S, t); } return(new HSBColor(h, s, Mathf.Lerp(a.m_B, b.m_B, t), Mathf.Lerp(a.m_A, b.m_A, t))); }