Creating an Editor snap-to-grid drawn by a gizmo
If the positions of objects need to be restricted to specific increments, it is useful to have a grid drawn in the Scene panel to help ensure that new objects are positioned based on those values, as well as code to snap objects to that grid.
In this recipe, we’ll use gizmos to draw a grid with a customizable grid size, color, number of lines, and line length. The result of following this recipe will look as follows:
Figure 19.3: Example of a visible grid to which objects have been snapped
How to do it...
To create an Editor snap-to-grid drawn by a gizmo, follow these steps:
- Create a new Unity 3D project.
- In the Scene panel, turn off the Skybox view (or simply toggle off all the visual settings) so that you have a plain background for your grid:
Figure 19.4: Turning off the Skybox view in the Scene panel
- Updating the display and the child objects will be performed...