See if a Color is Within a Threshold

I’m looking for a fast/easy way to simply compare two Color or Color32 objects to apply a threshold to one of my scripts. The script just needs to see if a color is within the range of two colors given by a field. I couldn’t find any method provided by the Unity API, and I was wondering if anyone on here might have a good solution. Thanks for any help!

bool isRedGood = checkedColor.r >= Mathf.Min(color1.r, color2.r) && checkedColor.r <= Mathf.Max(color1.r, color2.r);

bool isGreenGood = checkedColor.g >= Mathf.Min(color1.g, color2.g) && checkedColor.g <= Mathf.Max(color1.g, color2.g);

bool isBlueGood = checkedColor.b >= Mathf.Min(color1.b, color2.b) && checkedColor.b <= Mathf.Max(color1.b, color2.b);

bool isAlphaGood = checkedColor.a >= Mathf.Min(color1.a, color2.a) && checkedColor.a <= Mathf.Max(color1.a, color2.a);// May not need this one if you don't have an alpha channel :P

return isRedGood && isGreenGood && isBlueGood && isAlphaGood;

Assuming you don’t know at run-time which color has the max and min for any of the color channels. However, if you do know that, then it’s even easier:

bool isRedGood = checkedColor.r >= min.r && checkedColor.r <= max.r;

bool isGreenGood = checkedColor.g >= min.g && checkedColor.g <= max.g;

bool isBlueGood = checkedColor.b >= min.b && checkedColor.b <= max.b;

bool isAlphaGood = checkedColor.a >= min.a && checkedColor.a <= max.a;

return isRedGood && isGreenGood && isBlueGood && isAlphaGood;