unity中FPS的设置与显示
2015-09-08 15:01
429 查看
做项目时,想实时显示FPS,限定FPS来减轻CPU和GPU的负荷。
注意,要限定FPS数值需要在Edit->Project Setting->Qualit中的VSync count改为Don't Sync
代码根据unity圣典中Time.realtimeSinceStartup 自游戏开始实时时间下的例子修改:
注意,要限定FPS数值需要在Edit->Project Setting->Qualit中的VSync count改为Don't Sync
代码根据unity圣典中Time.realtimeSinceStartup 自游戏开始实时时间下的例子修改:
using UnityEngine; using System.Collections; public class FpsScript : MonoBehaviour { public float UpdateInterval = 0.5F; //在每个updateInterval间隔处计算,帧/秒,这样显示就不会随意的改变 private float LastInterval; // Last interval end time 最后间隔结束时间 private int Frames = 0; // Frames over current interval 超过当前间隔帧 private float Fps; // Current FPS //当前FPS public UILabel label; //在NGUI的Label显示 void Start() { //Application.targetFrameRate=30; //限定帧数 LastInterval = Time.realtimeSinceStartup; //自游戏开始实时时间 Frames = 0; } void OnGUI() { label.text = "FPS" + Fps.ToString ("f2"); //显示两位小数 } void Update() { ++Frames; if (Time.realtimeSinceStartup > LastInterval + UpdateInterval) { Fps = Frames / (Time.realtimeSinceStartup - LastInterval); Frames = 0; LastInterval = Time.realtimeSinceStartup; } } }
相关文章推荐
- Unity 3D 技能释放的脚本 技能冷却时间
- unity之警告“You can't place widgets on a layer different than the UIPanel that manages them.”
- Unity 3D 第三更
- Unity 3D第二更
- Unity 3D 第一更
- unity警告“Tiled GPU perf. warning: RenderTexture color surface (0x0) was not cleared/discarded, doin”
- Unity Application
- unity5 动画系统Mecanim事件快速入门 区分animation和animator不再混淆
- Unity3D学习之设置背景图片脚本解析
- Unity 内存管理
- Unity学习疑问记录之 动作动画忽略timeScale
- unity3d与android 交互问题
- [2015/09/08] Unity3D飞机大战(简陋版) Practice
- Unity使用AnimatorOverrudeController动态替换AnimationClip
- Unity3D教程:手游开发常用排序算法
- Unity中把字符串保存成文件的2种方式
- Unity 2D游戏开发教程之游戏中精灵的跳跃状态
- Unity 3D更新公告
- Unity 2D游戏开发教程之游戏中精灵的跳跃状态
- Unity笔记,onUnitCircle