How it works...
The EditorGridGizmoMenuItem script class adds a new item to the GameObject menu. When selected, a new GameObject is added to the Hierarchy 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 new grid positions.
The SnapToGridGizmo script class includes an Editor attribute [ExecuteInEditMode] so that it will receive Update() ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access