版本: Unity 6 (6000.0)
语言英语
  • C#

OnDemandRendering.effectiveRenderFrameRate

建议更改

成功!

感谢您帮助我们提高 Unity 文档的质量。虽然我们无法接受所有提交内容,但我们确实阅读了用户提出的每项建议更改,并在适用的情况下进行更新。

关闭

提交失败

由于某些原因,您的建议更改无法提交。请<a>稍后重试</a>。感谢您花时间帮助我们提高 Unity 文档的质量。

关闭

取消

public static int effectiveRenderFrameRate;

描述

当前估计的每秒渲染帧率,四舍五入到最接近的整数。

这是一个估计值,可能无法根据应用程序实现。
如果 QualitySettings.vSyncCount 大于 0,则通过以下公式计算:

FPS = Resolution.refreshRate / QualitySettings.vSyncCount / OnDemandRendering.renderFrameInterval

如果 QualitySettings.vSyncCount 为 0 且 Application.targetFrameRate 也大于 0

FPS = Application.targetFrameRate / OnDemandRendering.renderFrameInterval

Android、iOS 和 tvOS 在没有指定其他值的情况下使用 30 FPS 作为默认帧率。在这种情况下,将返回 30 / OnDemandRendering.renderFrameInterval。所有其他平台都返回 Application.targetFrameRate 的值。

using UnityEngine;
using UnityEngine.Rendering;
using System.Collections;

// This example shows how to use effectiveRenderFrameRate to ensure your application renders at a given frame rate regardless of // settings that could be changed by the user. Also demonstrates use of setting renderFrameInterval from a coroutine. public class Example : MonoBehaviour { void Start() { const int myTargetFrameRate = 10;

// Start off assuming that Application.targetFrameRate is 60 and QualitySettings.vSyncCount is 0 OnDemandRendering.renderFrameInterval = 6;

// Some applications may allow the user to modify the quality level. So we may not be able to rely on // the framerate always being a specific value. For this example we want the effective framerate to be 10. // If it is not then check the values and adjust the frame interval accordingly to achieve the framerate that we desire. if (OnDemandRendering.effectiveRenderFrameRate != 10) { if (QualitySettings.vSyncCount > 0) { OnDemandRendering.renderFrameInterval = (Screen.currentResolution.refreshRate / QualitySettings.vSyncCount / myTargetFrameRate); } else { OnDemandRendering.renderFrameInterval = (Application.targetFrameRate / myTargetFrameRate); } }

StartCoroutine(SlowRenderingFor5Seconds()); }

IEnumerator SlowRenderingFor5Seconds() { // After 5 seconds go back to rendering every frame yield return new WaitForSeconds(5); OnDemandRendering.renderFrameInterval = 1; }

void Update() { // For 5 seconds this will report that the effective framerate is 10. Afterward it will log what the framerate is given the current // quality and target framerate settings. Debug.Log("FrameRate: " + OnDemandRendering.effectiveRenderFrameRate); } }