Rendering.OnDemandRendering.renderFrameInterval

Unity · Версия 2020.3 LTS · Scripting · OnDemandRendering

Rendering.OnDemandRendering.renderFrameInterval

public static int renderFrameInterval;

Описание

Получить или установить текущий интервал частоты кадров. Чтобы восстановить отрисовку обратно к значению Application.targetFrameRate или QualitySettings.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;
        }
    }
}

Обновлено 17 ноября 2026 г.