在Unity3d 中能够通过代码设置 来限定游戏帧率。

Application.targetFrameRate=-1;

设置为 -1 表示不限定帧率。

转自http://blog.csdn.net/huutu

一般在手机游戏中我们限定帧率为30 就OK了。

Application.targetFrameRate=30;

可是把这个代码加入到project之后。在Unity中执行起来发现并没有什么卵用。。。

转自http://blog.csdn.net/huutu

于是到官网查看资料

http://docs.unity3d.com/ScriptReference/Application-targetFrameRate.html
Application.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 来打开渲染质量设置面板。

watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvaHV1dHU=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="">

转自http://blog.csdn.net/huutu

1、首先关掉垂直同步。如上图。

设置帧率为100

watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvaHV1dHU=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="">

然后执行后的帧率是 100.

watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvaHV1dHU=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="">

2、设置垂直同步为1

能够看到帧率为 60 帧左右跳动,全然无视了代码中的设定。

转自http://blog.csdn.net/huutu

3、设定垂直同步为 2

能够看到帧率在 30帧左右跳动。

转自http://blog.csdn.net/huutu

在游戏中显示帧率代码:

using 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 帧率设置 及在游戏执行时显示帧率的更多相关文章

  1. jmeter 通过csv data set config 设置参数化后,执行结果显示为<EOF>

    通过csv data set config 设置参数化后,执行结果显示为<EOF>: 反复确认相应的参数的设置均没有问题,其中csv文件编码方式采用uft-8.在csv data set ...

  2. jquery mobile 请求数据方法执行时显示加载中提示框

    在jquery mobile开发中,经常需要调用ajax方法,异步获取数据,如果异步获取数据方法由于网速等等的原因,会有一个反应时间,如果能在点击按钮后数据处理期间,给一个正在加载的提示,客户体验会更 ...

  3. 看代码学知识之(2) ListView无数据时显示其他View

    看代码学知识之(2) ListView无数据时显示其他View 今天看的一块布局是这样的: <!-- The frame layout is here since we will be show ...

  4. unity3D技术之事件函数的执行顺序[转]

    unity3D技术之事件函数的执行顺序 转自http://www.yxkfw.com/?p=13703   在unity的脚本,有大量的脚本执行按照预先确定的顺序执行的事件函数.此执行顺序说明如下: ...

  5. Unity3D笔记 愤怒的小鸟<五> 小鸟动画+Unity3D如何设置断点调式

    前言:实现小鸟的动画,之前吐槽过js写U3D,就改成了C#来写,没想到遇到问题了. 实现的效果 using UnityEngine; using System.Collections; /// < ...

  6. 执行时关闭标识位 FD_CLOEXEC 的作用

    首先先回顾 apue 中对它的描述: ① 表示描述符在通过一个 exec 时仍保持有效(书P63,3.14节 fcntl 函数,在讲 F_DUPFD 时顺便提到) ② 对打开文件的处理与每个描述符的执 ...

  7. 解决Button设置disabled后无法执行后台代码问题

    一.开始调式下面的程序,发现Button在js中设置disabled后无法执行后台代码(btnsave_Click)问题 <asp:Button ID="btnsave" r ...

  8. OpenNI结合Unity3D Kinect进行体感游戏开发(转)

    OpenNI结合Unity3D Kinect进行体感游戏开发(转) 楼主# 更多 发布于:2012-07-17 16:42     1. 下载安装Unity3D(目前版本为3.4)2. 下载OpenN ...

  9. Windows计划任务执行时不显示窗口的问题

    最近开发了工具,带界面的,需要定时执行的,为了方便直接用Windows计划任务做定时了.跑了一段时间发现,进程中也有,就是看不到程序的界面,进程的执行貌似也阻塞了. 从网上查了下,发现时启动方式的问题 ...

随机推荐

  1. shell实例浅谈之六文件特定行打印的多种方法

    一.问题 Sed和AWK在处理文件方面有很强的优势,还有head和tail等文件处理工具的使用,grep也可实现文本的搜索.上述命令都可以在后面直接加文件名,不需要在前面使用cat添加管道,cat会影 ...

  2. xml校验问题

    struts2使用xml校验 按照书本输入dtd约束文件 "-//OpenSymphony Group//XWork Validator 1.0.2//EN""http: ...

  3. LinuxC安装gcc

    使用centos进行C编程的时候使用gcc hello.c提示 bash:gcc:command not found 此时需要给Linux安装gcc命令如下 1 yum -y install gcc ...

  4. Android开发 第一篇

    关于android开发,new项目通知: 之前的new -> android project,现在更改为new -> android application project,同学们可以继续 ...

  5. Python3 官方文档翻译 - 4.7 函数定义

    4.7.1 默认函数定义 最常用的就是为一个或多个参数设定默认值,这让函数可以用比定义时更少的参数来调用,例如: def ask_ok(prompt, retries=4, complaint='Ye ...

  6. 【C++继承与派生之二】有子对象的派生类的构造函数

    这是我今天看书刚刚看到的,觉着以前对这一块内容了解不多,所以整理一下分享给大家.首先要介绍一下子对象的概念.类的数据成员不仅可以是int.char这样的基本类型,也可以是类对象,如可以包含这样的数据成 ...

  7. 第二种:NSObject

    - (void)viewDidLoad { [super viewDidLoad]; /** * 开启子线程的方式之一:NSObject */ // 第一个参数:selector // 第二个参数:方 ...

  8. Codeforces Round #315 (Div. 2B) 569B Inventory 贪心

    题目:Click here 题意:给你n,然后n个数,n个数中可能重复,可能不是1到n中的数.然后你用最少的改变数,让这个序列包含1到n所有数,并输出最后的序列. 分析:贪心. #include &l ...

  9. 小猪猪逆袭成博士之C++基础篇(二) 常量、处理类型、自定义头文件

    小猪猪逆袭成博士之C++基础篇(二) const .auto. decltype 上一章我们介绍了一些常用的类型和常见的问题,下面再介绍一些学习的时候不是特别常用但是在实际工程中很有用的一些东西. 一 ...

  10. c语言中malloc realloc 和calloc的联系与区别

    (1)C语言跟内存分配方式 <1>从静态存储区域分配.       内存在程序编译的时候就已经分配好,这块内存在程序的整个运行期间都存在.例如全局变量.static变量.<2> ...