Unity 根据您加载或卸载 场景场景包含游戏的环境和菜单。可以将每个唯一的场景文件视为一个唯一的关卡。在每个场景中,您可以放置环境、障碍物和装饰物,本质上是分段设计和构建您的游戏。 了解更多信息
参见 词汇表 的方式,以不同的方式更新其 光探针光探针存储有关光线如何穿过场景空间的信息。在给定空间内排列的光探针集合可以改善该空间内移动物体和静态 LOD 场景的光照效果。 了解更多信息
参见 词汇表 数据。
Unity 使用 LightProbes C# 对象来存储所有当前加载场景的光探针数据。LightProbes
对象包含一个称为四面体细分的内部数据结构。Unity 在其计算中使用四面体细分来确定光探针如何照亮 游戏对象Unity 场景中的基本对象,可以代表角色、道具、场景、摄像机、路点等。游戏对象的功能由附加到它的组件定义。 了解更多信息
参见 词汇表.
加载或卸载场景时,Unity 会自动更新 LightProbes
对象,使其包含所有当前加载场景中所有光探针的位置和系数。但是,Unity 是否更新四面体细分取决于您加载或卸载场景的方式。
使用 LoadSceneMode.Single 加载场景时,Unity 会在加载过程中自动更新四面体细分,因为新的光探针数据将完全替换以前的光探针数据。
使用 LoadSceneMode.Additive 加载场景,或使用 UnloadSceneAsync 卸载场景时,Unity 不会自动更新四面体细分,因为需要重新计算新的或移除的光探针数据 - 这是一项计算量大的操作,并且在此操作之后可能还有后续场景需要加载或卸载。
因此,Unity 提供了 needsRetetrahedralization 事件,允许您决定何时重新细分新的光探针数据。例如,如果您要附加加载五个新场景,则不希望在每个场景加载后重新细分数据五次。相反,您只希望在所有五个场景加载完毕并且所有新的光探针数据准备就绪后才重新细分数据。
如果 Unity 使用过时的四面体细分执行计算,则结果将不考虑任何新加载或卸载的光探针。这意味着光探针可能无法按预期照亮游戏对象,并且调用 LightProbes.CalculateInterpolatedLightAndOcclusionProbes() 或 LightProbes.GetInterpolatedProbe() 可能会返回意外结果。
要强制 Unity 更新四面体细分,可以调用 LightProbes.Tetrahedralize 或 LightProbes.TetrahedralizeAsync()。这些函数会导致 Unity 使用所有当前加载场景中所有光探针的数据更新四面体细分。
更新四面体细分是 CPU 密集型操作,CPU 影响会随着光探针数量的增加而增加。如果您正在加载和卸载多个场景,并且遇到更新四面体细分带来的性能影响,那么将更新延迟到您加载或卸载一定数量的内容,或者延迟到 CPU 影响不太可能影响应用程序性能的时间,可能会有所帮助。
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.