private const float __MAJOR_GRID_SIZE = 120f;
private const float __NODE_GRID_SIZE = 12f;
internal static void _DrawGrid(Rect position, Color majorColor, Color minorColor)
{
if (Event.current.type != EventType.Repaint) return;
//new HandleUtility().GetType().GetMethod("ApplyWireMaterial", BindingFlags.NonPublic | BindingFlags.Static).Invoke(null, null);
GL.PushMatrix();
GL.Begin(1);
__DrawGridLines(position, __NODE_GRID_SIZE, minorColor);
__DrawGridLines(position, __MAJOR_GRID_SIZE, majorColor);
GL.End();
GL.PopMatrix();
}
internal static Rect _SnapPositionToGrid(Rect position)
{
int num = Mathf.RoundToInt(position.x/__NODE_GRID_SIZE);
int num2 = Mathf.RoundToInt(position.y/__NODE_GRID_SIZE);
position.x = num*__NODE_GRID_SIZE;
position.y = num2*__NODE_GRID_SIZE;
return position;
}
private static void __DrawGridLines(Rect position, float gridSize, Color gridColor)
{
GL.Color(gridColor);
for (float i = position.xMin - position.xMin%gridSize; i < position.xMax; i += gridSize) __DrawLine(new Vector2(i, position.yMin), new Vector2(i, position.yMax));
GL.Color(gridColor);
for (float j = position.yMin - position.yMin%gridSize; j < position.yMax; j += gridSize) __DrawLine(new Vector2(position.xMin, j), new Vector2(position.xMax, j));
}
private static void __DrawLine(Vector2 p1, Vector2 p2)
{
GL.Vertex(p1);
GL.Vertex(p2);
}