Introduction
This plugin provides essential tools to accelerate your workflow for 2D and UI game object positioning within Unity 2D, Unity GUI Canvas and NGUI.
The Ruler 2D toolset is similar to the 2D layout tools provided by industry standard software like Adobe Photoshop or Adobe Illustrator. It provides rulers in the Scene View, the ability to drag guides from the rulers, a comprehensive alignment & distribution toolbox, a measuring tool, and a Grid creation panel with the ability to snap objects to the grid.
You can work with 3D scenes as well as long as the Scene View is set to 2D orthographic view mode.
To launch the plugin select Window ▶ Ruler 2D ▶ Open from the Unity menu bar. Alternatively you can use the CMD + \ shortcut on Mac or CTRL + \ on Windows.
Note that the plugin ships with its full source code (found in the R2D folder) and can be modified and enhanced with new functionality to suit any special scenarios.
The Settings Panel
Context
The Context dropdrown changes the coordinate system for Ruler 2D allowing you to work with either the standard Unity 2D view, a Unity GUI Canvas or NGUI. If you have a Unity GUI Canvas in the scene for example, the coordinate system will shift to respect the way objects are measured within the canvas, including scaling and origin.
Make sure you always set your Context correctly before working with the Unity GUI Canvas or NGUI since the default setting is the standard Unity 2D view. This dropdown will be populated with new context options only when Ruler 2D detects a Canvas or NGUI root on the scene.
Show Selected Coordinates
Enabling this option displays selected object coordinates in the Scene View.
Prefer Colliders
When Prefer Colliders is checked, Ruler 2D will use selected objects attached colliders instead of render bounds for all Toolbox operations. If an object does not have a collider it will fallback to the object render bounds.
Show Guides
This checkbox hides or shows the guides in the Scene View. You can also use the shortcut keys CMD + ; on Mac or CTRL + ; on Windows to toggle this setting. You can also lock the guides into position using the Option + CMD + ; keys on MAC or Alt + CMD + ; keys on Windows.
Snap Guides To Integer
You create guides by dragging from the rulers on the Scene View and then release to set the guide in place. If this setting is enabled, the guide will snap to the nearest integer value on the ruler.
Snap Edges To Guides
The Toolbox has a tool that allows you to snap objects to guides that you have set in the Scene View. Enabling this setting, will snap the objects to the guides using the object edges as opposed to the center of the objects.
The Toolbox
Align
Select two or more objects in the Hierarchy in order to enable the align tools. Note that enabling ‘Prefer Colliders’ in the Settings Panel allows you to work with colliders instead of render bounds (visual appearance of the object).The tools above perform the following operations in order:
• Align top edges to the highest top edge
• Align vertical centers to the average vertical center
• Align bottom edges to the lowest bottom edge
• Align left edges to the left most edge
• Align horizontal centers to the average horizontal center
• Align right edges to the right most edge
Distribute
Select three or more objects in the Hierarchy in order to enable the distribute tools. The distribute operation maintains boundary object positions based on the selected edge type (or center) and then averages out the spacing of the object edges (or centers) between the two boundary objects. The tools above perform the following operations in order:
• Distribute objects based on their top edges
• Distribute objects based on their vertical centers
• Distribute objects based on the bottom edges
• Distribute objects based on their left edges
• Distribute objects based on their horizontal centers • Distribute objects based on their right edges
Spacing
The spacing operations allow you to insert a speci ed amount of hori- zontal or vertical space between selected objects. The lowest X coordinate and lowest Y coordinates are maintained while the rest of the objects are adjusted. Note that the objects must be visually placed in the correct se- quence for proper results and the order of selection is ignored.
Snap To Guides
These operations are enabled when you have objects selected and their
are horizontal or vertical guides visible in the Scene View. They allow you to snap the selected objects to the guides in the direction indicated on the tool. Note that the ‘Snap Edges To Guides’ option in the Settings Panel al- lows you to specify whether you want to use object edges vs object centers. The tools above perform the following operations in order:
• Snap to the nearest guide towards left
• Snap to the nearest guide towards right • Snap to the nearest guide upward
• Snap to the nearest guide downward
Measure
The Measure tool allows you to draw a measuring line in the Scene View and read its length and angle. You can also select two objects and automatically draw a measuring line between the two.
• To draw a measuring line, press the ruler button and the Scene View will be ready for you to draw the line. Note that you cannot select objects in the Scene when the measure tool is ready. Pressing the button again or com- pleting the measuring line disables the measuring tool.
• To draw a measuring line between two objects, select the objects and press the distance button.
• To clear the existing measuring line, press the eraser button.
Clear Guides
This button will permanently delete all the guides in the Scene View. Note that if you want to temporarily hide the guides instead you can toggle the ‘Show Guides’ checkbox in the Settings Panel. You can also use the shortcut keys CMD + Shift + H on Mac or CTRL + Shift + H on Windows to show or hide guides.
The Grid Panel
Display Grid
This checkbox toggles the grid’s visibility in the Scene View.
Columns
Set the number of columns in the grid.
Rows
Set the number of rows in the grid.
Unit Horizontal Width
Sets the width of a single cell within the grid. This is relative to the current Context that has been selected in the Settings Panel.
Unit Vertical Height
Sets the height of a single cell within the grid. This is relative to the current Context that has been selected in the Settings Panel.
Origin X
Sets the bottom left origin’s X value. This is relative to the Context that has been selected in the Settings Panel.
Origin Y
Sets the bottom left origin’s Y value. This is relative to the Context that has been selected in the Settings Panel.
Snap To Grid
When Snap To Grid is enabled, you can drag and drop an object into a cell on the grid. The object’s center will automatically snap with the center of the cell when you release the mouse or trackpad.
Toggle Unity Grid
Use this to hide or show the default grid that appears in the Scene View. You can use the shortcut keys CMD + ‘ on Mac or CTRL + ‘ on Windows in order to toggle grid display.