使用 OnDemandRendering 类可控制和查询有关与所有其他子系统(例如物理、输入或动画)无关的渲染速度的信息。
下面是一些可能要降低帧率的示例情形:
1. 菜单(例如,应用程序入口点或暂停菜单):菜单往往是相对简单的场景,因此无需全速渲染。可以按较低帧率渲染菜单,以减少功耗并防止设备温度升高而导致 CPU 频率可能会受到限制。
2. 基于回合的游戏(例如国际象棋):玩家会花时间等待其他用户行棋或是考虑其下一步行棋。在低活动时间段中,可以降低帧率以防止不必要的功耗并延长电池续航时间。
3. 内容在大多数时间内是静态的应用程序(如汽车 UI)。
使用自适应性能包或只是想管理功耗和设备散热以尽可能延长电池续航时间并防止 CPU 受到限制时,调整渲染速度会特别有意义。
注意:VR 应用程序不支持按需渲染。不渲染每帧会导致视觉效果与头部移动不同步,可能会增大晕动症风险。
如果在 Android 上将此功能与 Optimized Frame Pacing 一起使用,请注意以下事项:
如果还使用 OpenGL ES,则 Optimized Frame Pacing 在帧率为 20、30 或 60 帧/秒时效果最好。若要确保以其中一个帧率进行渲染,请使用 OnDemandRendering.effectiveRenderFrameRate。
Vulkan 不那么严格,可使用更多数量的有效帧率。
如果请求使用不兼容的帧率,则应用程序会以尽可能快的速度进行渲染。另请注意,太高的 renderFrameInterval 可能会导致应用程序无响应,因为渲染帧之间的时间太长。
请注意事件执行:
此页面上的图描述每帧中的事件执行顺序。但是,在 Unity 不渲染(OnDemandRendering.willCurrentFrameRender 为 false 时)的帧期间,特定于渲染的事件(包括用于场景渲染、辅助图标渲染、GUI 渲染和帧结束部分的事件)不会发生。
effectiveRenderFrameRate | 渲染的当前估计速率,以每秒帧数为单位,舍入为最接近的整数。 |
renderFrameInterval | 获取或设置当前帧率间隔。若要将渲染恢复为 Application.targetFrameRate 或 QualitySettings.vSyncCount 的值,请将此设置为 0 或 1。 |
willCurrentFrameRender | 如果渲染当前帧,则为 True。 |
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.