Unity3d 帧率设置 及在游戏运行时显示帧率
2018-03-09 18:32
302 查看
版权声明:本文转自http://blog.csdn.net/huutu 转载请带上 http://www.liveslives.com/ http://blog.csdn.net/cp790621656/article/details/46645743在Unity3d 中可以通过代码设置 来限定游戏帧率。
[csharp] view plain copyApplication.targetFrameRate=-1;
设置为 -1 表示不限定帧率。 转自http://blog.csdn.net/huutu
一般在手机游戏中我们限定帧率为30 就OK了。
[csharp] view plain copyApplication.targetFrameRate=30;
但是把这个代码添加到工程之后,在Unity中运行起来发现并没有什么卵用。。。。
转自http://blog.csdn.net/huutu
于是到官网查看资料
[html] view plain copyhttp://docs.unity3d.com/ScriptReference/Application-targetFrameRate.html
[plain] view plain copyApplication.targetFrameRate
public static int targetFrameRate;
Description
Instructs game to try to render at a specified frame rate.
Setting targetFrameRate to -1 (the default) makes standalone games render as fast as they can,
and web player games to render at 50-60 frames/second depending on the platform.
Note that setting targetFrameRate does not guarantee that frame rate.
There can be fluctuations due to platform specifics, or the game might not achieve the frame rate because the computer is too slow.
If vsync is set in quality setting, the target framerate is ignored, and the vblank interval is used instead.
The vBlankCount property on qualitysettings can be used to limit the framerate to half of the screens refresh rate
(60 fps screen can be limited to 30 fps by setting vBlankCount to 2)
targetFrameRate is ignored in the editor.
大意就是说:
Application.targetFrameRate 是用来让游戏以指定的帧率运行,如果设置为 -1 就让游戏以最快的速度运行。
但是 这个 设定会 垂直同步 影响。
如果设置了垂直同步,那么 就会抛弃这个设定 而根据 屏幕硬件的刷新速度来运行。
如果设置了垂直同步为1,那么就是 60 帧。
如果设置了为2 ,那么就是 30 帧。
点击 菜单 Editor -> ProjectSetting -> QualitySettings 来打开渲染质量设置面板。
转自http://blog.csdn.net/huutu
1、首先关掉垂直同步,如上图。
设置帧率为100
然后运行后的帧率是 100.
2、设置垂直同步为1
可以看到帧率为 60 帧左右跳动,完全无视了代码中的设定。
转自http://blog.csdn.net/huutu
3、设定垂直同步为 2
可以看到帧率在 30帧左右跳动。
转自http://blog.csdn.net/huutu
在游戏中显示帧率代码:
[csharp] view plain copyusing UnityEngine;
using System.Collections;
using DG.Tweening;
public class NewBehaviourScript : MonoBehaviour
{
private float m_LastUpdateShowTime=0f; //上一次更新帧率的时间;
private float m_UpdateShowDeltaTime=0.01f;//更新帧率的时间间隔;
private int m_FrameUpdate=0;//帧数;
private float m_FPS=0;
void Awake()
{
Application.targetFrameRate=100;
}
// Use this for initialization
void Start ()
{
m_LastUpdateShowTime=Time.realtimeSinceStartup;
}
// Update is called once per frame
void Update ()
{
m_FrameUpdate++;
if(Time.realtimeSinceStartup-m_LastUpdateShowTime>=m_UpdateShowDeltaTime)
{
m_FPS=m_FrameUpdate/(Time.realtimeSinceStartup-m_LastUpdateShowTime);
m_FrameUpdate=0;
m_LastUpdateShowTime=Time.realtimeSinceStartup;
}
}
void OnGUI()
{
GUI.Label(new Rect(Screen.width/2,0,100,100),"FPS: "+m_FPS);
}
}
官网文档中的最后一句……经测试在编辑器状态下是有效的。。
[csharp] view plain copyApplication.targetFrameRate=-1;
设置为 -1 表示不限定帧率。 转自http://blog.csdn.net/huutu
一般在手机游戏中我们限定帧率为30 就OK了。
[csharp] view plain copyApplication.targetFrameRate=30;
但是把这个代码添加到工程之后,在Unity中运行起来发现并没有什么卵用。。。。
转自http://blog.csdn.net/huutu
于是到官网查看资料
[html] view plain copyhttp://docs.unity3d.com/ScriptReference/Application-targetFrameRate.html
[plain] view plain copyApplication.targetFrameRate
public static int targetFrameRate;
Description
Instructs game to try to render at a specified frame rate.
Setting targetFrameRate to -1 (the default) makes standalone games render as fast as they can,
and web player games to render at 50-60 frames/second depending on the platform.
Note that setting targetFrameRate does not guarantee that frame rate.
There can be fluctuations due to platform specifics, or the game might not achieve the frame rate because the computer is too slow.
If vsync is set in quality setting, the target framerate is ignored, and the vblank interval is used instead.
The vBlankCount property on qualitysettings can be used to limit the framerate to half of the screens refresh rate
(60 fps screen can be limited to 30 fps by setting vBlankCount to 2)
targetFrameRate is ignored in the editor.
大意就是说:
Application.targetFrameRate 是用来让游戏以指定的帧率运行,如果设置为 -1 就让游戏以最快的速度运行。
但是 这个 设定会 垂直同步 影响。
如果设置了垂直同步,那么 就会抛弃这个设定 而根据 屏幕硬件的刷新速度来运行。
如果设置了垂直同步为1,那么就是 60 帧。
如果设置了为2 ,那么就是 30 帧。
点击 菜单 Editor -> ProjectSetting -> QualitySettings 来打开渲染质量设置面板。
转自http://blog.csdn.net/huutu
1、首先关掉垂直同步,如上图。
设置帧率为100
然后运行后的帧率是 100.
2、设置垂直同步为1
可以看到帧率为 60 帧左右跳动,完全无视了代码中的设定。
转自http://blog.csdn.net/huutu
3、设定垂直同步为 2
可以看到帧率在 30帧左右跳动。
转自http://blog.csdn.net/huutu
在游戏中显示帧率代码:
[csharp] view plain copyusing UnityEngine;
using System.Collections;
using DG.Tweening;
public class NewBehaviourScript : MonoBehaviour
{
private float m_LastUpdateShowTime=0f; //上一次更新帧率的时间;
private float m_UpdateShowDeltaTime=0.01f;//更新帧率的时间间隔;
private int m_FrameUpdate=0;//帧数;
private float m_FPS=0;
void Awake()
{
Application.targetFrameRate=100;
}
// Use this for initialization
void Start ()
{
m_LastUpdateShowTime=Time.realtimeSinceStartup;
}
// Update is called once per frame
void Update ()
{
m_FrameUpdate++;
if(Time.realtimeSinceStartup-m_LastUpdateShowTime>=m_UpdateShowDeltaTime)
{
m_FPS=m_FrameUpdate/(Time.realtimeSinceStartup-m_LastUpdateShowTime);
m_FrameUpdate=0;
m_LastUpdateShowTime=Time.realtimeSinceStartup;
}
}
void OnGUI()
{
GUI.Label(new Rect(Screen.width/2,0,100,100),"FPS: "+m_FPS);
}
}
官网文档中的最后一句……经测试在编辑器状态下是有效的。。
相关文章推荐
- Unity3d 帧率设置 及在游戏运行时显示帧率
- Unity3d帧率设置及在游戏运行时显示帧率
- Unity3d 帧率设置 及在游戏执行时显示帧率
- 帧率设置 及在游戏运行时显示帧率
- Unity3D显示帧率以及设置不限制帧率
- Unity3D设置字体颜色大小,用于游戏分数显示设置等,
- Unity3D显示帧率以及设置不限制帧率
- unity3d设置3D模型显示在2D背景之前(多个相机分层显示)(转)
- VS2005设置(显示行号,更改字体,添加运行按钮)
- Unity3D 官方文档 2D游戏的起始2 2D物理 全局设置与刚体
- [Unity3D]查看与设置游戏帧数FPS
- Unity3d NGUI Slider设置游戏背景音乐的音量
- Unity3D -- 编辑器注入lua代码到游戏运行
- unity3d web 平台运行相关设置
- 【UNITY3D 游戏开发之八】Unity编译到iPhone运行 Collider 无法正常触发事件解决方案
- javascript设置asp.net程序开始运行时ie最大化显示
- C# 调用 Emgu.CV 显示RTSP流 + 设置程序运行超时时间
- Unity3D 设置帧频及显示FPS
- [Unity3D]总结使用Unity 3D优化游戏运行性能的经验
- Unity3D显示帧率以及设置垂直同步