Unity 的场景可见性控件可用于在 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 视图控制栏中的场景可见性开关会显示场景中隐藏的游戏对象的数量。单击此开关可开启和关闭场景可见性。
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 视图会暂时覆盖场景可见性设置,以便仅显示所选的游戏对象,而其他所有对象被隐藏。
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
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.