Scripts that we place in a folder named Editor are known as Editor scripts, and in such scripts, we can customize and extend the features and look-and-feel of the Unity Editor. In this recipe, we've created Editor scripts to display and limit the movement of scene objects in a grid.
The EditorGridGizmoMenuItem script class adds a new item to the GameObject menu. When selected, a new GameObject is added to the Hierarchy window named ___snap-to-grid___, positioned at (0, 0, 0), and containing an instance object component of the GridGizmo script class.
GridGizmo draws a 2D grid based on public properties for grid size, color, number of lines, and line length. Regarding the SetGrid(...) method, as well as updating the integer grid size variable grid, it also invokes the SnapAllChildren() method so that each time the grid size is changed, all child GameObjects are snapped into the...