Version: 2019.1
使用自定义 Editor 工具
Scene 视图控制栏

Scene Visibility

Unity 的场景可见性控件可用于在 Scene 视图中快速隐藏和显示游戏对象,而无需更改它们在游戏中的可见性。这可用于处理难以查看和选择特定游戏对象的大型或复杂场景。

Selected GameObjects are highlighted in orange
Selected GameObjects are highlighted in orange
更改场景可见性设置会在 Scene 视图中隐藏选定的游戏对象
更改场景可见性设置会在 Scene 视图中隐藏选定的游戏对象

使用可见性选项比停用游戏对象更安全,因为可见性选项仅影响 Scene 视图。这意味着不会从渲染的场景中意外删除游戏对象或触发光照、遮挡和其他系统的不必要烘焙作业。

Unity 将场景可见性设置保存到项目的 Library 文件夹中名为 SceneVisibilityState.asset 的文件中。场景会自动从该文件读取可见性设置,并在可见性设置每次更改时进行自动更新。这样,相关设置就可从一个会话持续到下一个会话。由于 Unity 的源代码控制设置通常会忽略 Library 文件夹,因此更改可见性设置应该不会造成源代码控制方面的冲突。

为游戏对象及其子项设置场景可见性

可以从 Hierarchy 窗口控制各个游戏对象在场景中的可见性。

每个游戏对象都有场景可见性图标/开关
每个游戏对象都有场景可见性图标/开关

要切换场景可见性,请执行以下操作:

  • Click a GameObject’s visibility icon in the Hierarchy window, or press H, to hide/show the GameObject and its children.

    Toggling visibility for an object and its children affects all child objects, from the “target” object all the way down to the bottom of the hierarchy.

  • Alt + Click a GameObject’s visibility icon in the Hierarchy window to hide/show the GameObject only.

    Toggling visibility for a single object does not affect its children. They retain whatever visibility status they had previously.

  • Click the scene’s visibility icon to hide/show everything in the scene.

由于可以切换整个分支或单个游戏对象的可见性,因此最后游戏对象变为可见状态,但子项或父项为隐藏状态。为了帮助跟踪发生的情况,可见性图标会改变以指示每个游戏对象的状态。

A 游戏对象可见,但是其某些子项被隐藏。
B 游戏对象被隐藏,但是其某些子项可见。
C 游戏对象及其子项可见。仅当鼠标悬停在游戏对象上时,才会显示此图标。
D 游戏对象及其子项被隐藏。

在 Hierarchy 窗口中进行的场景可见性更改是持久有效的。每当在 Scene 视图中关闭和再次开启场景可见性、关闭然后重新打开场景或进行其他操作时,Unity 都会重新应用这些更改。

开启和关闭场景可见性

Scene 视图控制栏中的场景可见性开关会显示场景中隐藏的游戏对象的数量。单击此开关可开启和关闭场景可见性。

The Scene visibility counter shows 14 hidden GameObjects in this scene
The Scene visibility counter shows 14 hidden GameObjects in this scene
  • Turning Scene visibility off essentially mutes the Scene visibility settings you set in the Hierarchy window, but doesn’t delete or change them. All hidden GameObjects are temporarily visible.

  • Turning Scene visibility back on re-applies the visibility settings set in the Hierarchy window.

隔离所选的游戏对象

Isolation 视图会暂时覆盖场景可见性设置,以便仅显示所选的游戏对象,而其他所有对象被隐藏。

Isolation 视图会覆盖场景可见性设置,因此只有所选对象及其子项 (A) 可见。<br/>单击 Exit 按钮 (B) 会恢复以前的场景可见性设置。
Isolation 视图会覆盖场景可见性设置,因此只有所选对象及其子项 (A) 可见。
单击 Exit 按钮 (B) 会恢复以前的场景可见性设置。

To enter the Isolation view, press Shift + H.

这样可隔离所有选定的游戏对象及其子项。隔离隐藏的游戏对象会使这些游戏对象可见,直到退出 Isolation 视图。

在 Isolation 视图中时,可以继续更改场景可见性设置,但是所做的任何更改都会在退出时丢失。

To exit the Isolation view, press Shift + H again, or click the Exit button in the Scene view.

退出 Isolation 视图将恢复原始的场景可见性设置。


  • 2019–05–07 页面已发布并进行了编辑审查

  • 2019.1 中添加了场景可见性选项 NewIn20191

使用自定义 Editor 工具
Scene 视图控制栏