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

OnDemandRendering.renderFrameInterval

建议更改

成功!

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

关闭

提交失败

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

关闭

取消

public static int renderFrameInterval;

描述

获取或设置当前帧率间隔。要将渲染恢复到Application.targetFrameRateQualitySettings.vSyncCount的值,请将其设置为 0 或 1。

using UnityEngine;
using UnityEngine.Rendering;

// This example shows how to get and set the current frame rate interval and what you can do with that information. public class Example : MonoBehaviour { void Start() { QualitySettings.vSyncCount = 0; Application.targetFrameRate = 60; OnDemandRendering.renderFrameInterval = 6; }

void Update() { if (Input.GetMouseButton(0) || (Input.touchCount > 0)) { // If the mouse button or a finger is down render at 60 FPS (every frame). OnDemandRendering.renderFrameInterval = 1; } else { // If there isn't any input then we can go back to 10 FPS (every 6 frames). OnDemandRendering.renderFrameInterval = 6; }

// We've decided to lower the frame rate by increasing the frame interval. Perhaps in a pause menu. // There may be some other systems that we don't need at that time. if (OnDemandRendering.renderFrameInterval > 1) { // Disable physics Physics.autoSimulation = false;

// Disable other systems or turn down audio volume for example. } else { // If we are back to the normal framerate turn physics back on. Physics.autoSimulation = true; } } }