Version: 2022.3
Tags
Save your work

静态游戏对象

如果游戏对象在运行时未移动,则被称为静态游戏对象。如果游戏对象在运行时移动,则被称为动态游戏对象

Unity 中的许多系统都可以在 Editor 中预计算有关静态游戏对象的信息。由于静态游戏对象不会移动,因此这些计算的结果在运行时仍然有效。这意味着 Unity 可以节省运行时计算成本,并可能提高性能。

Static Editor Flags 属性

在 Inspector 中查看游戏对象时显示的 Static Editor Flags 复选框和下拉菜单
在 Inspector 中查看游戏对象时显示的 Static Editor Flags 复选框和下拉菜单

Static Editor Flags 属性列出了许多 Unity 系统,这些系统的预计算中可以包含一个静态游戏对象。使用下拉选单可定义哪些系统应在它们的预计算中包含此游戏对象。在运行时设置 Static Editor Flag 对这些系统没有影响。

仅当系统需要了解某个游戏对象时,才应该将这个游戏对象包含在预计算中。如果系统无需了解某个游戏对象,但仍然将这个游戏对象包含在预计算中,可能会导致计算资源浪费、产生不必要的大数据文件或意外行为。

Static Editor Flags 属性位于游戏对象的 Inspector 的最右上角。这个属性包含一个复选框(将值设置为 EverythingNothing)和一个下拉菜单(可选择要包含的值)。

还可以使用 GameObjectUtility.SetStaticEditorFlags API 和 GameObject.isStatic 在代码中设置 Static Editor Flags 属性。

可用值如下:

属性: 功能:
Nothing 对于任何系统,都不将游戏对象包含在预计算中。
Everything 对于下方的任何系统,都将游戏对象包含在预计算中。
Contribute GI When you enable this property, Unity includes the target Mesh Renderer in global illumination calculations. These calculations take place while precomputing lighting data at bake time. The ContributeGI property exposes the ReceiveGI property. The ContributeGI property only takes effect if you enable a global illumination setting such as Baked Global Illumination or Enlighten Realtime Global Illumination for the target Scene. A Unity Blog post about static lighting with Light Probes provides guidance for using this flag. For additional context, see this tutorial for setting up the Built-in Render Pipeline and lighting in Unity.
Occluder Static 在遮挡剔除系统中,将游戏对象标记为静态遮挡物。有关更多信息,请参阅有关遮挡剔除系统的文档。
Occludee Static 在遮挡剔除系统中,将游戏对象标记为静态被遮挡物。有关更多信息,请参阅有关遮挡剔除系统的文档。
Batching Static 将游戏对象的网格与其他符合条件的网格组合起来,有可能降低运行时渲染成本。有关更多信息,请参阅有关静态批处理的文档。
Navigation Static 在预计算导航数据时包含游戏对象。有关更多信息,请参阅有关导航系统的文档。
Off Mesh Link Generation Attempt to generate an OffMesh Link that starts from this GameObject when precomputing navigation data. For more information, see the documentation on automatically building OffMesh Links.
Reflection Probe Type 属性设置为 Baked反射探针预计算数据时,包含此游戏对象。有关更多信息,请参阅有关反射探针的文档。
Tags
Save your work