Make grid and snap to it in Unity editor (2D Game)

We are building a 2D game like this - I’ve been using Unity for a while, but have never had to build a grid system like this.

Ideally this would be our pipeline:

  1. We use orthographic camera
  2. All art is broken up into power of two dimensions
  3. We draw all the art in perspective
  4. My level designers just drag and drop buildings, road etc, and they snap to a grid perfectly

Any thoughts on bringing a game like this to pass in Unity (grid based)?

11982-1.jpg

you can make a script that executes in edit mode.

[ExecuteInEditMode]
public class EditModeGridSnap : MonoBehaviour {
	public float snapValue = 1;
	public float depth = 0;	
	
	void Update() {
		float snapInverse = 1/snapValue;
		
		float x, y, z;
		
		// if snapValue = .5, x = 1.45 -> snapInverse = 2 -> x*2 => 2.90 -> round 2.90 => 3 -> 3/2 => 1.5
		// so 1.45 to nearest .5 is 1.5
		x = Mathf.Round(transform.position.x * snapInverse)/snapInverse;
		y = Mathf.Round(transform.position.y * snapInverse)/snapInverse;   
		z = depth;  // depth from camera
		
		transform.position = new Vector3(x, y, z);
	}
}

You may need to adjust the script depending on if objects are odd or even dimension, because it changes the centers, i.e. a cube .75 wide needs different math than a cube 1 unit wide when snapping to the nearest .25 units.

I see there is a feature called Unit Snapping. Click ctrl while dragging and object will move by the amount defined on Edit->Snap Settings

Source