如果游戏对象在运行时未移动,则被称为静态游戏对象。如果游戏对象在运行时移动,则被称为动态游戏对象。
Unity 中的许多系统都可以在 Editor 中预计算有关静态游戏对象的信息。由于静态游戏对象不会移动,因此这些计算的结果在运行时仍然有效。这意味着 Unity 可以节省运行时计算成本,并可能提高性能。
Static Editor Flags 属性列出了许多 Unity 系统,这些系统的预计算中可以包含一个静态游戏对象。使用下拉选单可定义哪些系统应在它们的预计算中包含此游戏对象。在运行时设置 Static Editor Flag 对这些系统没有影响。
仅当系统需要了解某个游戏对象时,才应该将这个游戏对象包含在预计算中。如果系统无需了解某个游戏对象,但仍然将这个游戏对象包含在预计算中,可能会导致计算资源浪费、产生不必要的大数据文件或意外行为。
Static Editor Flags 属性位于游戏对象的 Inspector 的最右上角。这个属性包含一个复选框(将值设置为 Everything 或 Nothing)和一个下拉菜单(可选择要包含的值)。
还可以使用 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 | Mark the GameObject as a Static Occluder in the occlusion culling system. For more information, refer to the Occlusion Culling system. |
Occludee Static | Mark the GameObject as a Static Occludee in the occlusion culling system. For more information, refer to the Occlusion Culling system. |
Batching Static | Combine the GameObject’s Mesh with other eligible Meshes, to potentially reduce runtime rendering costs. For more information, refer to the documentation on Static Batching. |
Navigation Static | Include the GameObject when precomputing navigation data. For more information, refer to the Navigation system. |
Off Mesh Link Generation | Attempt to generate an OffMesh Link that starts from this GameObject when precomputing navigation data. For more information, refer to the documentation for automatically building OffMesh Links. |
Reflection Probe | Include this GameObject when precomputing data for Reflection Probes whose Type property is set to Baked. For more information, refer to Reflection Probes. |