指定 Unity 尝试渲染游戏的目标帧率。
一个大于 0 的整数,或特殊值 -1(默认值)。
桌面和网页:如果 QualitySettings.vSyncCount 设置为 0,则 Application.targetFrameRate
会为游戏选择目标帧率。如果 vSyncCount != 0
,则忽略 targetFrameRate
。
Android 和 iOS:移动平台始终忽略 QualitySettings.vSyncCount,而是使用 Application.targetFrameRate
为游戏选择目标帧率。使用 targetFrameRate
控制游戏的帧率。这对于限制游戏的帧率很有用,可以确保游戏在繁重的渲染工作负载下流畅且稳定地显示。您还可以降低游戏的帧率以节省电池电量并在移动设备上避免过热。
当 QualitySettings.vSyncCount = 0
且 Application.targetFrameRate = -1
时
- 桌面:内容以尽可能快的速度异步渲染。
- 网页:内容以原生显示器刷新率渲染。
- Android 和 iOS:内容以固定 30 fps 渲染以节省电量,与显示器的原生刷新率无关。
桌面和网页:建议使用 QualitySettings.vSyncCount
而不是 Application.targetFrameRate
,因为 vSyncCount
实现了一种基于硬件的同步机制,而 targetFrameRate
是一种基于软件的定时方法,容易出现微卡顿。换句话说,在桌面和网页平台上,设置 vSyncCount = 0
并使用 targetFrameRate
不会产生完全无卡顿的输出。当需要平滑的帧速率时,始终使用 vSyncCount > 0
。
网页、Android 和 iOS:渲染始终受显示器最大刷新率的限制。将 vSyncCount
设置为 0 并将 targetFrameRate
设置为任意高值都不会超过显示器的原生刷新率,即使渲染工作负载足够低。
Android 和 iOS:要在显示器的原生刷新率下渲染,请将 Application.targetFrameRate
设置为 Resolution.refreshRateRatio 字段(位于 Screen.currentResolution 属性中)的值。
iOS:显示器的原生刷新率由 Apple 的ProMotion功能控制。当项目中禁用 ProMotion(新项目的默认设置)时,原生刷新率为 60 Hz。启用 ProMotion 时,支持 ProMotion 的 iOS 显示器的原生刷新率为 120 Hz,否则为 60 Hz。
Android 和 iOS:如果指定的速率不能均匀地划分显示器的当前刷新率,则 Application.targetFrameRate
的值将向下舍入到最接近的可以均匀划分的数字。例如,在 60Hz 的 Android 显示器上运行时,如果 Application.targetFrameRate = 25
,则内容实际上以 20fps 渲染,因为 20 是低于 25 且可以均匀划分 60 的最大数字。
VR 平台
VR 平台会忽略 QualitySettings.vSyncCount 和 Application.targetFrameRate
,而是由 VR SDK 控制帧率。
Unity 编辑器
在编辑器中,Application.targetFrameRate
仅影响游戏视图。它对其他编辑器窗口没有影响。
其他资源:QualitySettings.vSyncCount、Screen.currentResolution。
using UnityEngine;
public class Example { void Start() { // Limit framerate to cinematic 24fps. QualitySettings.vSyncCount = 0; // Set vSyncCount to 0 so that using .targetFrameRate is enabled. Application.targetFrameRate = 24; } }
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.