Mimic mecanim's grid in background

I try to reproduce mecanim’s background for my tool. I know i should use Handles.DrawLine or similar but i wonder on size behaviour (flat pixel? or % of screen resolution?) small and big square and its color/alpha and width line

there any suggestion or Unity people can answer to my specific question? I would be very grateful for that :wink:

You mean the AnimatorController grid? That’s drawn using the GL API, see:

Hard to know what colour, width, opacity you should use. The Mecanim grid is just black with different transparency for minor and major lines.

Wouldn’t it be easier to use a tiled texture?

Here’s some c#. Drop this grid.cs onto a camera. Think this is what you’ll need.

//cs example
using UnityEngine;
using System.Collections;

public class grid : MonoBehaviour {

	private Rect m_LastGraphExtents;
		private static readonly Color kGridMinorColorDark  = new Color (0f, 0f, 0f, 0.18f);
		private static readonly Color kGridMajorColorDark  = new Color (0f, 0f, 0f, 0.28f);

	void Start () {
		CreateLineMaterial();
	}
	
	void OnGUI()
	{
		DrawGrid();
	}
	
	void DrawGrid ()
	{
		if (Event.current.type != EventType.Repaint)
			return;

		lineMaterial.SetPass(0);
		
		GL.PushMatrix ();
		GL.Begin (GL.LINES);
		
		DrawGridLines (10.0f, kGridMinorColorDark);
		
		DrawGridLines (50.0f, kGridMajorColorDark);
			
		GL.End ();
		GL.PopMatrix ();
		
	}
	
	private void DrawGridLines (float gridSize, Color gridColor)
	{
		GL.Color (gridColor);
		for (float x = 0.0f; x < Screen.width; x += gridSize)
			DrawLine (new Vector2 (x, 0.0f), new Vector2 (x, Screen.height));
		GL.Color (gridColor);
		for (float y = 0.0f; y < Screen.height; y += gridSize)
			DrawLine (new Vector2 (0.0f, y), new Vector2 (Screen.width, y));
	}
	
	private void DrawLine (Vector2 p1, Vector2 p2)
	{
		GL.Vertex (p1);
		GL.Vertex (p2);
	}


	private Material lineMaterial;
	
	private void CreateLineMaterial()
	{
		if( !lineMaterial ) {
			lineMaterial = new Material( "Shader \"Lines/Colored Blended\" {" +
				"SubShader { Pass { " +
				"    Blend SrcAlpha OneMinusSrcAlpha " +
				"    ZWrite Off Cull Off Fog { Mode Off } " +
				"    BindChannels {" +
				"      Bind \"vertex\", vertex Bind \"color\", color }" +
				"} } }" );
			lineMaterial.hideFlags = HideFlags.HideAndDontSave;
			lineMaterial.shader.hideFlags = HideFlags.HideAndDontSave;
		}
	}

}

Thank you very much!