- Home /
Question by
MikeFRBR · Aug 17, 2017 at 12:08 AM ·
colornavmeshnavigationarea
How can I get the pre-defined color of a NavMesh area ?
Hi everybody,
Firstly, since I'm new and this is my first action in the Unity Community, nice to meet you !
I would like to know if it exists an API call to get the pre-defined color (as we can see in the "Navigation" panel under "Areas" section) of a particular NavMesh area, giving its name or its identifier ?
Unfortunately, I have not been successful on finding it in the API documentation.
Thanks in advance for the help !
Comment
Answer by MikeFRBR · Oct 08, 2017 at 06:01 PM
Is anybody here that knows this information ? Is it something possible to do ?
Answer by tarahugger · Dec 14, 2018 at 05:37 PM
This should do it
// UnityEditor.NavMeshEditorWindow
private Color GetAreaColor(int i)
{
Color result;
if (i == 0)
{
result = new Color(0f, 0.75f, 1f, 0.5f);
}
else
{
int num = (this.Bit(i, 4) + this.Bit(i, 1) * 2 + 1) * 63;
int num2 = (this.Bit(i, 3) + this.Bit(i, 2) * 2 + 1) * 63;
int num3 = (this.Bit(i, 5) + this.Bit(i, 0) * 2 + 1) * 63;
result = new Color((float)num / 255f, (float)num2 / 255f, (float)num3 / 255f, 0.5f);
}
return result;
}
And as a copy and pas$$anonymous$$ble solution:
private static int Bit(int a, int b)
{
return (a & (1 << b)) >> b;
}
private static Color GetAreaColor(int i)
{
if (i == 0)
return new Color(0, 0.75f, 1.0f, 0.5f);
int r = (Bit(i, 4) + Bit(i, 1) * 2 + 1) * 63;
int g = (Bit(i, 3) + Bit(i, 2) * 2 + 1) * 63;
int b = (Bit(i, 5) + Bit(i, 0) * 2 + 1) * 63;
return new Color((float)r / 255.0f, (float)g / 255.0f, (float)b / 255.0f, 0.5f);
}