Unity 在 Editor 的 Scene 视图中提供了可视化网格,可通过将游戏对象对齐(移动)到最近的网格位置来帮助精确对齐游戏对象。
可以通过几种方式沿 X、Y 或 Z 轴将游戏对象与网格对齐:
还能以增量方式变换游戏对象,而无需将其与网格线对齐。如果需要更改移动、旋转或缩放的量,则可以更改递增的对齐值。
默认情况下,网格是隐藏的,但是可以使其可见并可切换沿着哪个轴显示。可以通过更改以下设置来自定义网格的外观和行为:
其中很多操作都支持键盘快捷键。可以查看为这些操作分配了哪些组合键,并使用 Shortcuts Manager 对其进行自定义。
可以从菜单 (Edit > Grid and Snap Settings) 中或使用网格可见性下拉菜单打开 Grid and Snap 窗口:
从网格可见性下拉菜单 (A) 中,单击溢出菜单图标 (B)。
选择 Edit Grid and Snap Settings (C)。
在 Grid and Snap 窗口中,可以执行以下操作:
注意:__Grid and Snap__ 窗口上的设置在所有 Scene 视图中是全局适用的。
本节提供有关如何执行以下操作的信息:
可以将游戏对象对齐到单个轴上的最近网格点,也可以一次性在所有轴上对齐游戏对象。
要将游戏对象与特定轴的网格上的最近点对齐,请执行以下操作:
从 Align Selection to Grid 部分中,单击与您要推动到的轴相对应的 X、Y 或 Z 按钮。
要一次性在所有轴上对齐游戏对象,请执行以下操作:
选择要与网格对齐的游戏对象。
使用 Ctrl+\ (Windows) 或 Command+\ (macOS) 快捷键将游戏对象推动到所有轴上的网格上。
或者,可以打开 Grid and Snap 窗口,然后单击 Align Selection to Grid 部分中的 All Axes 按钮。
要开启自动贴靠网格,请执行以下操作:
启用自动网格贴靠时,__Move、Rotate__ 和 Scale 变换工具会沿激活的辅助图标轴将选定的游戏对象贴靠到网格。如果需要游戏对象以较小的增量移动,也可以采用增量方式变换游戏对象。
要按增量贴靠值来移动、旋转或缩放,请执行以下操作:
要更改默认的增量贴靠值,请执行以下操作:
打开 Grid and Snap 窗口。
Increment Snap 部分包含几个属性,可用于为所有轴设置相同的值或不同的值:
Move: With the link icon selected, enter a uniform increment snap value for all axes, or unlink the axes and set different increment snap values in the X, Y, and Z axis properties.
Rotate: Enter a rotation increment value in degrees.
Scale: Enter a scale increment value as a scale factor. For example, if the Scale value is 2, the selected GameObject will scale at an increment of twice its original size.
本节提供有关自定义以下设置的信息:
可以在 Scene 视图工具栏上切换网格可见性按钮 () 以便在任何轴(X、Y、Z)上显示或隐藏网格。如果处于正交模式,则 Unity 会选择正确的视图。
要更改显示网格的轴,请执行以下操作:
从工具栏中打开网格可见性下拉菜单 ()。
从 Grid Axis 部分中,选择希望显示网格的轴。
可以使用 Grid and Snap 窗口来设置网格线在 Scene 视图中显示的大小。这会影响网格的外观以及游戏对象自动贴靠网格的方式,但不会影响游戏对象移动、旋转或缩放的增量。
如果一次性为所有轴设置一个大小,则会显示一个均匀(正方形)网格。但是,也可以在三个轴的任何一个轴上使用不同的值,从而查看非均匀(矩形)网格。默认情况下,网格设置为均匀距离(所有轴上为 1)。
要调整网格的大小,请执行以下操作:
打开 Grid and Snap 窗口。
World Grid 部分包含几个属性,可用于为所有轴设置相同的值或不同的值:
使用所选链接图标的 Size 属性为可视网格(所有网格线的长度相同)输入均匀值,或取消轴的链接并为 X、Y 和 Z 指定网格线之间的非均匀距离。
例如,要在 x 和 y 轴上创建矩形网格,可取消轴的链接并将 X 和 Y 设置为 1,将 Z 设置为 2。
如果要切换回网格线之间的均匀值,请执行以下操作:
注意:还可以使用键盘快捷键来增大和减小网格的大小:
要在 Scene 视图中更改可见网格线的颜色,请执行以下操作:
打开 Unity 的 Preferences 页面(在 Windows 上选择 Edit > Preferences 或在 macOS 上选择 Unity > Preferences)。
从列表中单击 Colors 类别以查看 Colors 页面。
使用 Grid 属性的拾色器选择一种新颜色。
如果网格线太浅或太深,可以进行调整:
从工具栏中打开网格可见性下拉菜单 ()。
从 Grid Settings 部分中,调整 Opacity 属性的值。
还可以使用以下快捷键沿网格的轴前后移动网格:
微移网格可以使其更近(例如,如果很难从远处的网格中看到游戏对象)或将其移到更远处。
要将网格轴和不透明度设置重置为其默认值,请执行以下操作:
从工具栏中打开网格可见性下拉菜单 ()。
单击溢出菜单图标,然后单击 Reset。
网格再次出现在 y 轴上,不透明度为 0.5,但网格线的可见性保持不变。
要将网格的大小重置为默认值,请执行以下操作:
通过以下任一方法打开 Grid and Snap 窗口:
在 World Grid 标题旁边,单击齿轮图标 ()。
单击 Reset。
只有 World Grid 部分下的值会恢复为 1。
要将增量贴靠值重置为默认值,请执行以下操作:
通过以下任一方法打开 Grid and Snap 窗口:
在 Increment Snap 标题旁边,单击齿轮图标 ()。
单击 Reset。
只有 Increment Snap 部分下的值会恢复为其原始默认值。
可以使用默认 Unity 快捷键执行以下操作:
操作 | 默认快捷键 |
---|---|
增大网格大小 |
Ctrl+] (Windows) 或 Command+] (macOS) |
减小网格大小 |
Ctrl+[ (Windows) 或 Command+[ (macOS) |
向后微移网格 | Shift+[ |
向前微移网格 | Shift+] |
推动到网格(将所选对象与网格对齐) |
Ctrl+\ (Windows) 或 Command+\ (macOS) |
重置网格 | (默认情况下没有快捷键) |
要更改这些默认快捷键,请使用 Shortcuts Manager。
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.